forked from fuwutu/CodeForces
-
Notifications
You must be signed in to change notification settings - Fork 0
/
166A - Rank List.cpp
41 lines (37 loc) · 903 Bytes
/
166A - Rank List.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
//4042740 Jul 9, 2013 6:04:04 PM fuwutu 166A - Rank List GNU C++0x Accepted 15 ms 0 KB
#include <iostream>
#include <algorithm>
using namespace std;
struct team
{
int problems;
int penaltytime;
};
bool cmp(const team& left, const team& right)
{
return left.problems > right.problems
|| (left.problems == right.problems && left.penaltytime < right.penaltytime);
}
int main()
{
int n, k;
team t[50];
cin >> n >> k;
for (int i = 0; i < n; ++i)
{
cin >> t[i].problems >> t[i].penaltytime;
}
sort(t, t + n, cmp);
k -= 1;
int l(k), r(k);
while (l > 0 && t[l-1].problems == t[k].problems && t[l-1].penaltytime == t[k].penaltytime)
{
l -= 1;
}
while (r + 1 < n && t[r+1].problems == t[k].problems && t[r+1].penaltytime == t[k].penaltytime)
{
r += 1;
}
cout << r - l + 1 << endl;
return 0;
}