codeforces-scrape

Codeforces scraped problems and editorials
git clone git://git.laack.co/codeforces-scrape.git
Log | Files | Refs | README

1073D.md (2338B)


      1 Source: https://codeforces.com/problemset/problem/1073/D
      2 
      3 D. Berland Fair
      4 
      5 time limit per test
      6 
      7 2 seconds
      8 
      9 memory limit per test
     10 
     11 256 megabytes
     12 
     13 input
     14 
     15 standard input
     16 
     17 output
     18 
     19 standard output
     20 
     21 XXI Berland Annual Fair is coming really soon! Traditionally fair consists of $n$ booths, arranged in a circle. The booths are numbered $1$ through $n$ clockwise with $n$ being adjacent to $1$. The $i$-th booths sells some candies for the price of $a_i$ burles per item. Each booth has an unlimited supply of candies.
     22 
     23 Polycarp has decided to spend at most $T$ burles at the fair. However, he has some plan in mind for his path across the booths:
     24 
     25 * at first, he visits booth number $1$;
     26 * if he has enough burles to buy exactly one candy from the current booth, then he buys it immediately;
     27 * then he proceeds to the next booth in the clockwise order (regardless of if he bought a candy or not).
     28 
     29 Polycarp's money is finite, thus the process will end once he can no longer buy candy at any booth.
     30 
     31 Calculate the number of candies Polycarp will buy.
     32 
     33 Input
     34 
     35 The first line contains two integers $n$ and $T$ ($1 \le n \le 2 \cdot 10^5$, $1 \le T \le 10^{18}$) — the number of booths at the fair and the initial amount of burles Polycarp has.
     36 
     37 The second line contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$) — the price of the single candy at booth number $i$.
     38 
     39 Output
     40 
     41 Print a single integer — the total number of candies Polycarp will buy.
     42 
     43 Examples
     44 
     45 Input
     46 
     47 ```
     48 3 38  
     49 5 2 5
     50 ```
     51 
     52 Output
     53 
     54 ```
     55 10
     56 ```
     57 
     58 Input
     59 
     60 ```
     61 5 21  
     62 2 4 100 2 6
     63 ```
     64 
     65 Output
     66 
     67 ```
     68 6
     69 ```
     70 
     71 Note
     72 
     73 Let's consider the first example. Here are Polycarp's moves until he runs out of money:
     74 
     75 1. Booth $1$, buys candy for $5$, $T = 33$;
     76 2. Booth $2$, buys candy for $2$, $T = 31$;
     77 3. Booth $3$, buys candy for $5$, $T = 26$;
     78 4. Booth $1$, buys candy for $5$, $T = 21$;
     79 5. Booth $2$, buys candy for $2$, $T = 19$;
     80 6. Booth $3$, buys candy for $5$, $T = 14$;
     81 7. Booth $1$, buys candy for $5$, $T = 9$;
     82 8. Booth $2$, buys candy for $2$, $T = 7$;
     83 9. Booth $3$, buys candy for $5$, $T = 2$;
     84 10. Booth $1$, buys no candy, not enough money;
     85 11. Booth $2$, buys candy for $2$, $T = 0$.
     86 
     87 No candy can be bought later. The total number of candies bought is $10$.
     88 
     89 In the second example he has $1$ burle left at the end of his path, no candy can be bought with this amount.