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 | /// Raihan Ruhin
/// CSE, Jahangirnagar University.
/// Dhaka-Bangladesh.
/// id: raihanruhin (topcoder / codeforces / codechef / uva ), 3235 (lightoj)
/// mail: raihanruhin@ (yahoo / gmail / facebook)
/// blog: ruhinraihan.blogspot.com
#include<bits/stdc++.h>
using namespace std;
#define SET(a) memset(a,-1,sizeof(a))
#define CLR(a) memset(a,0,sizeof(a))
#define PI acos(-1.0)
#define MOD 1000000007
#define MX 100010
struct match{
int score, receive;
bool operator < (const match &m) const{
return m.score-m.receive < score-receive ;
}
};
match mth[MX];
int main()
{
ios_base::sync_with_stdio(0);cin.tie(0);
int tc,kk=1, n, g;
//cin>>tc;
while(cin>>n>>g)
{
for(int i=0;i<n;i++)
cin>>mth[i].score>>mth[i].receive;
sort(mth, mth+n);
int point = 0;
for(int i=0;i<n;i++)
{
//cout<<mth[i].score<<" "<<mth[i].receive<<endl;
if(mth[i].score>mth[i].receive)
point += 3;
else if(mth[i].score==mth[i].receive)
{
if(g>0)
{
point += 3;
g--;
}
else point += 1;
}
else if(mth[i].score<mth[i].receive)
{
if(g>(mth[i].receive-mth[i].score))
{
point += 3;
g= g-(mth[i].receive-mth[i].score)-1;
}
else if(g==(mth[i].receive-mth[i].score))
{
point += 1;
g= g-(mth[i].receive-mth[i].score);
}
}
}
cout<<point<<endl;
}
return 0;
}
|
No comments:
Post a Comment