-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbee1495.cpp
More file actions
44 lines (38 loc) · 751 Bytes
/
Copy pathbee1495.cpp
File metadata and controls
44 lines (38 loc) · 751 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
/**
* Contest : Beecrowd
* Problem : Futebol
* Link : https://judge.beecrowd.com/pt/problems/view/1495
* Time : O(N logN)
*/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define fastio ios::sync_with_stdio(0); cin.tie(0);
int main() {
fastio
int n, g;
while (cin >> n >> g) {
vector<int> diffs;
int ans = 0;
while (n--) {
int a, b;
cin >> a >> b;
if (a <= b) diffs.push_back(b - a);
else ans += 3;
}
sort(diffs.begin(), diffs.end());
for (auto d : diffs) {
if (g > d) {
g -= (d + 1);
ans += 3;
}
else if (g == d) {
g -= d;
ans += 1;
}
else break;
}
cout << ans << '\n';
}
return 0;
}