#include <bits/stdc++.h>
#ifdef LOCAL
#include <bits/debug.hpp>
#endif // LOCAL
#define ll long long
#define all(x) x.begin(), x.end()
#define Neco "Schools"
#define resp(x) sort(all(x)), x.resize(unique(all(x)) - x.begin())
#define getbit(x,i) ((x >> i)&1)
#define _left id * 2, l, mid
#define _right id * 2 + 1, mid + 1, r
#define cntbit(x) __builtin_popcountll(x)
#define fi(i, a, b) for(int i = a; i <= b; i++)
#define fid(i, a, b) for(int i = a; i >= b; i--)
#define maxn (int) 2e5 + 7
using namespace std;
const ll mod = 1e9 + 7; //972663749
const ll base = 911382323;
int n, n1, n2;
pair<int, int> a[maxn];
multiset<int> S1;
set<pair<int, int>> S2, S3;
ll Sum;
void solve()
{
cin >> n >> n1 >> n2;
fi(i, 1, n) cin >> a[i].first >> a[i].second;
sort(a + 1, a + 1 + n, greater<>());
fi(i, 1, n) {
if(i <= n1) S1.insert(a[i].second - a[i].first), Sum += a[i].first;
else {
S2.insert({a[i].first, i});
S3.insert({a[i].second, i});
}
}
fi(_, 1, n2) {
int th = 0, Max = -1e18;
ll val = *S1.rbegin() + S2.rbegin()->first;
if(val > Max) {
Max = val, th = 1;
}
val = S3.rbegin()->first;
if(val > Max) {
Max = val, th = 2;
}
Sum += Max;
if(th == 1) {
int id = S2.rbegin() -> second;
S1.erase(prev(S1.end()));
S1.insert({a[id].first - a[id].second});
S2.erase({a[id].first, id});
S3.erase({a[id].second, id});
}
if(th == 2) {
int id = S3.rbegin() -> second;
S2.erase({a[id].first, id});
S3.erase({a[id].second, id});
}
}
cout << Sum;
}
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
if(fopen(Neco".inp", "r")) {
freopen(Neco".inp", "r", stdin);
freopen(Neco".out", "w", stdout);
}
int nTest = 1;
// cin >> nTest;
while(nTest--)
{
solve();
}
return 0;
}
Compilation message
school.cpp: In function 'void solve()':
school.cpp:45:27: warning: overflow in conversion from 'double' to 'int' changes value from '-1.0e+18' to '-2147483648' [-Woverflow]
45 | int th = 0, Max = -1e18;
| ^~~~~
school.cpp: In function 'int main()':
school.cpp:89:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
89 | freopen(Neco".inp", "r", stdin);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
school.cpp:90:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
90 | freopen(Neco".out", "w", stdout);
| ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Correct |
0 ms |
348 KB |
Output is correct |
4 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
5 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
6 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
7 |
Incorrect |
2 ms |
856 KB |
Output isn't correct |
8 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
9 |
Incorrect |
1 ms |
796 KB |
Output isn't correct |
10 |
Incorrect |
1 ms |
604 KB |
Output isn't correct |
11 |
Incorrect |
3 ms |
860 KB |
Output isn't correct |
12 |
Incorrect |
3 ms |
856 KB |
Output isn't correct |
13 |
Incorrect |
10 ms |
3028 KB |
Output isn't correct |
14 |
Incorrect |
41 ms |
8804 KB |
Output isn't correct |
15 |
Incorrect |
85 ms |
18320 KB |
Output isn't correct |
16 |
Incorrect |
140 ms |
19644 KB |
Output isn't correct |
17 |
Runtime error |
25 ms |
9300 KB |
Execution killed with signal 11 |
18 |
Runtime error |
24 ms |
9296 KB |
Execution killed with signal 11 |
19 |
Runtime error |
37 ms |
13892 KB |
Execution killed with signal 11 |
20 |
Runtime error |
37 ms |
13400 KB |
Execution killed with signal 11 |