# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
286188 | shrek12357 | Schools (IZhO13_school) | C++14 | 753 ms | 28996 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 <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <climits>
#include <cmath>
#include <fstream>
#include <queue>
using namespace std;
int main() {
int n, m, s;
cin >> n >> s >> m;
vector<pair<long long, long long>> music;
vector<pair<long long, long long>> nums;
multiset<pair<long long, long long>> left;
for (int i = 0; i < n; i++) {
long long a, b;
cin >> a >> b;
nums.push_back({ a, b });
music.push_back({ b, a });
left.insert({ -1*b, a });
}
sort(nums.begin(), nums.end());
sort(music.begin(), music.end());
int curIdx = n - m - 1;
//int bigIdx = n - 1;
long long ans = 0;
for(int i = nums.size() - 1; i >= 0; i--){
if (s <= 0) {
while (m > 0) {
ans += -1 * left.begin()->first;
left.erase(left.begin());
m--;
}
break;
}
if (curIdx >= 0 && nums[i].second < music[curIdx].first) {
s--;
ans += nums[i].first;
}
else {
long long num1 = nums[i].first;
if (i - s >= 0) {
num1 -= nums[i - s].first;
}
long long num2 = nums[i].second;
if (curIdx >= 0) {
num2 -= music[curIdx].first;
}
if (num1 > num2) {
curIdx--;
s--;
ans += nums[i].first;
}
else {
ans += nums[i].second;
m--;
}
}
left.erase(left.find({ nums[i].second * -1, nums[i].first }));
}
cout << ans << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |