#include <vector>
#include <iostream>
#include <cassert>
#include <random>
#include <cmath>
#include <map>
#include <algorithm>
#include <bitset>
#include <random>
#include <queue>
#include <set>
#include <stack>
#define ll int64_t
using namespace std;
bool comp (pair<int64_t, int64_t> p1, pair<int64_t, int64_t> p2) {
return (p1.first - p1.second < p2.first - p2.second);
}
void print (vector<ll> v) {
for (ll x: v) {
cout << x << ' ';
}
cout << endl;
}
vector<ll> get_max (vector<ll> v, int k) {
multiset<ll> best;
vector<ll> ans;
ans.push_back(-1e17);
ll sum = 0;
for (int i = 0; i < v.size(); i++) {
if (i <= k - 1) {
best.insert(v[i]);
sum += v[i];
} else {
if (v[i] >= *(best.begin())) {
sum -= *(best.begin());
best.erase(best.find(*(best.begin())));
sum += v[i];
best.insert(v[i]);
}
}
ans.push_back(((i >= k - 1) ? sum : -1e17));
/*
for (ll x: best) {
cout << x << " ";
}
cout << endl;
*/
}
return ans;
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N, M, S;
cin >> N >> M >> S;
vector<pair<ll,ll>> vec(N);
vec.resize(N);
for (int i = 0; i < N; i++) {
cin >> vec[i].first >> vec[i].second;
}
sort(vec.begin(), vec.end(), comp);
vector<ll> a, b;
for (int i = 0; i < N; i++) {
a.push_back(vec[i].first), b.push_back(vec[i].second);
}
reverse(a.begin(), a.end());
//print(a);
auto res1 = get_max(a, M);
//print(res1);
auto res2 = get_max(b, S);
reverse(res2.begin(), res2.end());
//print(res2);
int64_t ans = 0;
for (int i = 0; i <= N; i++) {
ans = max(ans, res1[i] + res2[i]);
//cout << res1[i] << " " << res2[i] << endl;
}
cout << ans;
}
Compilation message
school.cpp: In function 'std::vector<long int> get_max(std::vector<long int>, int)':
school.cpp:29:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
29 | for (int i = 0; i < v.size(); i++) {
| ~~^~~~~~~~~~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Execution timed out |
2076 ms |
212 KB |
Time limit exceeded |
3 |
Correct |
0 ms |
212 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
0 ms |
212 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
2 ms |
596 KB |
Output is correct |
8 |
Correct |
2 ms |
724 KB |
Output is correct |
9 |
Correct |
2 ms |
724 KB |
Output is correct |
10 |
Correct |
2 ms |
724 KB |
Output is correct |
11 |
Correct |
3 ms |
724 KB |
Output is correct |
12 |
Correct |
3 ms |
724 KB |
Output is correct |
13 |
Correct |
19 ms |
3656 KB |
Output is correct |
14 |
Correct |
36 ms |
6440 KB |
Output is correct |
15 |
Correct |
60 ms |
11276 KB |
Output is correct |
16 |
Correct |
125 ms |
17564 KB |
Output is correct |
17 |
Correct |
138 ms |
18204 KB |
Output is correct |
18 |
Correct |
143 ms |
18184 KB |
Output is correct |
19 |
Correct |
174 ms |
20244 KB |
Output is correct |
20 |
Correct |
181 ms |
25148 KB |
Output is correct |