CodeForces - 166A----Rank List

A. Rank List
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 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.

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.

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 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.
Output

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

7 2
4 10
4 10
4 10
3 20
2 1
2 1
1 10

Output
Copy

3

Input
Copy

5 4
3 1
3 1
5 3
3 1
3 1

Output
Copy

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.
解题思路
要找出与第K名相同的组,我们可以给一个权重,然后把两个数组变为一个数组。然后去判断。

package a;
import java.util.*;
public class P {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt(),k=sc.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++) {
			int arr=sc.nextInt(),brr=sc.nextInt();
			a[i]=arr*50-brr;
		}
		Arrays.sort(a);
		int count=0;
		for(int i=0;i<n;i++) {
			if(a[i]==a[n-k]) {
				count++;
			}
		}
		System.out.println(count);
	}
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值