A. Rank List

来源:互联网 发布:js全等与等于区别 编辑:程序博客网 时间:2024/05/21 17:37

time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

You know the rules of comparing the results of two given teams very well. Let's say that team a solved pa problems with total penalty time ta and team b solved pb problems with total penalty time tb. 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 pa > pb, or pa = pb and ta < tb.

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 + 1y + 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.

Your task is to count what number of teams from the given list shared the k-th place.

Input

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 pi and ti (1 ≤ pi, ti ≤ 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.

Output

In the only line print the sought number of teams that got the k-th place in the final results' table.

Sample test(s)
input
7 24 104 104 103 202 12 11 10
output
3
input
5 43 13 15 33 13 1
output
4
Note

The final results' table for the first sample is:

  • 1-3 places — 4 solved problems, the penalty time equals 10
  • 4 place — 3 solved problems, the penalty time equals 20
  • 5-6 places — 2 solved problems, the penalty time equals 1
  • 7 place — 1 solved problem, the penalty time equals 10

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.

The final table for the second sample is:

  • 1 place — 5 solved problems, the penalty time equals 3
  • 2-5 places — 3 solved problems, the penalty time equals 1

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.



解题说明:此题的问题主要是依据两个条件进行排序,不过可以通过分配不同的权重值让两个条件合并为一个条件,这里给的因子为50比1,确保了过题数能占较大比重。然后再找出有多少数字和第k位的相同即可。


#include<cstdio>#include<iostream>#include<algorithm>#include<cstring>#include<cmath>using namespace std;int main(){int n, k, A[50], i, con=0, a, b;scanf("%d %d",&n,&k);for(i=0; i<n; i++){scanf("%d %d",&a,&b);A[i]=a*50-b;}sort(A,A+n);for(i=0; i<n; i++){if(A[i]==A[n-k]){con++;}}printf("%d\n",con);return 0;}


原创粉丝点击