# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
756506 |
2023-06-11T18:26:31 Z |
Olympia |
Schools (IZhO13_school) |
C++17 |
|
199 ms |
25096 KB |
#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);
}
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));
}
return ans;
}
ll sum (vector<ll> v) {
ll ans = 0;
for (ll x: v) {
ans += x;
}
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);
}
if (S == 0) {
cout << get_max(a, M).back();
exit(0);
}
if (M == 0) {
cout << get_max(b, S).back();
exit(0);
}
reverse(a.begin(), a.end());
auto res1 = get_max(a, M);
auto res2 = get_max(b, S);
reverse(res2.begin(), res2.end());
int64_t ans = 0;
for (int i = 0; i <= N; i++) {
ans = max(ans, res1[i] + res2[i]);
}
cout << ans;
}
Compilation message
school.cpp: In function 'std::vector<long int> get_max(std::vector<long int>, int)':
school.cpp:23:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<long int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
23 | for (int i = 0; i < v.size(); i++) {
| ~~^~~~~~~~~~
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 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 |
764 KB |
Output is correct |
10 |
Correct |
3 ms |
672 KB |
Output is correct |
11 |
Correct |
2 ms |
724 KB |
Output is correct |
12 |
Correct |
3 ms |
724 KB |
Output is correct |
13 |
Correct |
20 ms |
3676 KB |
Output is correct |
14 |
Correct |
35 ms |
6356 KB |
Output is correct |
15 |
Correct |
62 ms |
11228 KB |
Output is correct |
16 |
Correct |
117 ms |
17572 KB |
Output is correct |
17 |
Correct |
146 ms |
18380 KB |
Output is correct |
18 |
Correct |
143 ms |
18276 KB |
Output is correct |
19 |
Correct |
158 ms |
20224 KB |
Output is correct |
20 |
Correct |
199 ms |
25096 KB |
Output is correct |