-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFootball.cpp
More file actions
56 lines (45 loc) · 779 Bytes
/
Football.cpp
File metadata and controls
56 lines (45 loc) · 779 Bytes
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
vector<int> v;
bool compare(int a, int b) { return (a > b); }
int main(int argc, char const *argv[])
{
int n, g, s, r, c, i, sz;
bool b;
while(scanf("%d %d", &n, &g) == 2)
{
c = 0;
v.clear();
for (i = 0; i < n; ++i)
{
scanf("%d %d", &s, &r);
if(s > r) c += 3;
else v.push_back(s - r);
}
sort(v.begin(), v.end(), compare);
sz = v.size();
b = false;
for (i = 0; i < sz; ++i)
{
if(b){
if(v[i] == 0) c++;
else break;
}else{
if(g <= 0) b = true;
if((1 - v[i]) <= g){
g -= (1 - v[i]);
c += 3;
}else if((0 - v[i]) == g){
c++;
g -= (0-v[i]);
}else{
b = true;
}
}
}
printf("%d\n", c);
}
return 0;
}