-
Notifications
You must be signed in to change notification settings - Fork 0
/
football.c
76 lines (61 loc) · 965 Bytes
/
football.c
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <stdio.h>
#include <stdlib.h>
#define MAX 100001
int cmpfunc(const void *va, const void *vb){
const char *ia = va;
const char *ib = vb;
if (*ia < *ib) return -1;
else if (*ia > *ib) return +1;
else return 0;
}
int main(){
int n, g;
int i;
int s, r;
int win, lose, draw;
int temp;
int points;
int lost[MAX];
while(scanf("%d %d",&n, &g) == 2){
i=0;
win = 0;
lose = 0;
draw = 0;
while(1){
if(i == n)
break;
scanf("%d %d",&s, &r);
temp = s - r;
if(temp == 0)
draw++;
else if(temp > 0)
win++;
else{
lost[lose] = temp*-1;
lose++;
}
i++;
}
if(lose > 0)
qsort(lost, lose, sizeof (int), cmpfunc);
i = 0;
while(1){
if(g == 0)
break;
if(draw != 0){
win++;
draw--;
g--;
}else if(lose != 0 && lost[i] <= g){
draw++;
lose--;
g = g - lost[i];
i++;
}else
break;
}
points = win*3 + draw;
printf("%d\n",points);
}
return 0;
}