codeforces-scrape

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

1165B.md (1523B)


      1 Source: https://codeforces.com/problemset/problem/1165/B
      2 
      3 B. Polycarp Training
      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 Polycarp wants to train before another programming competition. During the first day of his training he should solve exactly $1$ problem, during the second day — exactly $2$ problems, during the third day — exactly $3$ problems, and so on. During the $k$-th day he should solve $k$ problems.
     22 
     23 Polycarp has a list of $n$ contests, the $i$-th contest consists of $a_i$ problems. During each day Polycarp has to choose exactly one of the contests he didn't solve yet and solve it. He solves exactly $k$ problems from this contest. Other problems are discarded from it. If there are no contests consisting of at least $k$ problems that Polycarp didn't solve yet during the $k$-th day, then Polycarp stops his training.
     24 
     25 How many days Polycarp can train if he chooses the contests optimally?
     26 
     27 Input
     28 
     29 The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of contests.
     30 
     31 The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 2 \cdot 10^5$) — the number of problems in the $i$-th contest.
     32 
     33 Output
     34 
     35 Print one integer — the maximum number of days Polycarp can train if he chooses the contests optimally.
     36 
     37 Examples
     38 
     39 Input
     40 
     41 ```
     42 4
     43 3 1 4 1
     44 ```
     45 
     46 Output
     47 
     48 ```
     49 3
     50 ```
     51 
     52 Input
     53 
     54 ```
     55 3
     56 1 1 1
     57 ```
     58 
     59 Output
     60 
     61 ```
     62 1
     63 ```
     64 
     65 Input
     66 
     67 ```
     68 5
     69 1 1 1 2 2
     70 ```
     71 
     72 Output
     73 
     74 ```
     75 2
     76 ```