codeforces-scrape

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

166A.md (3060B)


      1 Source: https://codeforces.com/problemset/problem/166/A
      2 
      3 A. Rank List
      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 stdin
     16 
     17 output
     18 
     19 stdout
     20 
     21 Another programming contest is over. You got hold of the contest's final results table. The table has the following data. For each team we are shown two numbers: the number of problems and the total penalty time. However, for no team we are shown its final place.
     22 
     23 You know the rules of comparing the results of two given teams very well. Let's say that team *a* solved *p**a* problems with total penalty time *t**a* and team *b* solved *p**b* problems with total penalty time *t**b*. Team *a* gets a higher place than team *b* in the end, if it either solved more problems on the contest, or solved the same number of problems but in less total time. In other words, team *a* gets a higher place than team *b* in the final results' table if either *p**a* > *p**b*, or *p**a* = *p**b* and *t**a* < *t**b*.
     24 
     25 It is considered that the teams that solve the same number of problems with the same penalty time share all corresponding places. More formally, let's say there is a group of *x* teams that solved the same number of problems with the same penalty time. Let's also say that *y* teams performed better than the teams from this group. In this case all teams from the group share places *y* + 1, *y* + 2, ..., *y* + *x*. The teams that performed worse than the teams from this group, get their places in the results table starting from the *y* + *x* + 1-th place.
     26 
     27 Your task is to count what number of teams from the given list shared the *k*-th place.
     28 
     29 Input
     30 
     31 The first line contains two integers *n* and *k* (1 ≤ *k* ≤ *n* ≤ 50). Then *n* lines contain the description of the teams: the *i*-th line contains two integers *p**i* and *t**i* (1 ≤ *p**i*, *t**i* ≤ 50) — the number of solved problems and the total penalty time of the *i*-th team, correspondingly. All numbers in the lines are separated by spaces.
     32 
     33 Output
     34 
     35 In the only line print the sought number of teams that got the *k*-th place in the final results' table.
     36 
     37 Examples
     38 
     39 Input
     40 
     41 ```
     42 7 2  
     43 4 10  
     44 4 10  
     45 4 10  
     46 3 20  
     47 2 1  
     48 2 1  
     49 1 10
     50 ```
     51 
     52 Output
     53 
     54 ```
     55 3
     56 ```
     57 
     58 Input
     59 
     60 ```
     61 5 4  
     62 3 1  
     63 3 1  
     64 5 3  
     65 3 1  
     66 3 1
     67 ```
     68 
     69 Output
     70 
     71 ```
     72 4
     73 ```
     74 
     75 Note
     76 
     77 The final results' table for the first sample is:
     78 
     79 * 1-3 places — 4 solved problems, the penalty time equals 10
     80 * 4 place — 3 solved problems, the penalty time equals 20
     81 * 5-6 places — 2 solved problems, the penalty time equals 1
     82 * 7 place — 1 solved problem, the penalty time equals 10
     83 
     84 The table shows that the second place is shared by the teams that solved 4 problems with penalty time 10. There are 3 such teams.
     85 
     86 The final table for the second sample is:
     87 
     88 * 1 place — 5 solved problems, the penalty time equals 3
     89 * 2-5 places — 3 solved problems, the penalty time equals 1
     90 
     91 The table shows that the fourth place is shared by the teams that solved 3 problems with penalty time 1. There are 4 such teams.