# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
756504 | Olympia | Schools (IZhO13_school) | C++17 | 2076 ms | 25148 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |