codeforces-scrape

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

1133C.md (1702B)


      1 Source: https://codeforces.com/problemset/problem/1133/C
      2 
      3 C. Balanced Team
      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 You are a coach at your local university. There are $n$ students under your supervision, the programming skill of the $i$-th student is $a_i$.
     22 
     23 You have to create a team for a new programming competition. As you know, the more students some team has the more probable its victory is! So you have to create a team with the maximum number of students. But you also know that a team should be balanced. It means that the programming skill of each pair of students in a created team should differ by no more than $5$.
     24 
     25 Your task is to report the maximum possible number of students in a balanced team.
     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 students.
     30 
     31 The second line of the input contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is a programming skill of the $i$-th student.
     32 
     33 Output
     34 
     35 Print one integer — the maximum possible number of students in a balanced team.
     36 
     37 Examples
     38 
     39 Input
     40 
     41 ```
     42 6
     43 1 10 17 12 15 2
     44 ```
     45 
     46 Output
     47 
     48 ```
     49 3
     50 ```
     51 
     52 Input
     53 
     54 ```
     55 10
     56 1337 1337 1337 1337 1337 1337 1337 1337 1337 1337
     57 ```
     58 
     59 Output
     60 
     61 ```
     62 10
     63 ```
     64 
     65 Input
     66 
     67 ```
     68 6
     69 1 1000 10000 10 100 1000000000
     70 ```
     71 
     72 Output
     73 
     74 ```
     75 1
     76 ```
     77 
     78 Note
     79 
     80 In the first example you can create a team with skills $[12, 17, 15]$.
     81 
     82 In the second example you can take all students in a team because their programming skills are equal.
     83 
     84 In the third example you can create a team consisting of a single student (and you cannot create a team consisting of at least two students).