# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
756496 | Olympia | Schools (IZhO13_school) | C++17 | 2078 ms | 25760 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>
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);
}
multiset<int64_t> music;
multiset<int64_t> sport;
vector<pair<int64_t, int64_t>> vec;
void remove_music (pair<int64_t,int64_t> p) {
music.erase(music.find(p.first));
}
void add_sport (pair<int64_t,int64_t> p) {
sport.insert(p.second);
}
void add_music (pair<int64_t,int64_t> p) {
music.insert(p.first);
}
int64_t get_max(multiset<int64_t>& ms, int k) {
if (ms.size() < k) {
return -1e17;
}
vector<int64_t> vec;
for (auto& i: ms) {
vec.push_back(i);
}
int64_t ans = 0;
while (k != 0) {
ans += vec.back();
vec.pop_back();
k--;
}
return ans;
}
int64_t solve (int M, int S) {
multiset<pair<int,int>> ms;
if (M == 0) {
int64_t ans = 0;
for (auto& p: vec) {
ans += p.second;
}
return ans;
}
if (S == 0) {
int64_t ans = 0;
for (auto& p: vec) {
ans += p.first;
}
return ans;
}
sort(vec.begin(), vec.end(), comp);
for (int i = 0; i < vec.size(); i++) {
add_music(vec[i]);
}
int64_t ans = 0;
for (int i = 0; i < vec.size(); i++) {
remove_music(vec[i]);
add_sport(vec[i]);
ans = max(get_max(music, M) + get_max(sport, S), ans);
}
return ans;
}
int main () {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int N, M, S;
cin >> N >> M >> S;
vec.resize(N);
for (int i = 0; i < N; i++) {
cin >> vec[i].first >> vec[i].second;
}
cout << solve(M, S);
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |