Submission #286188

#TimeUsernameProblemLanguageResultExecution timeMemory
286188shrek12357Schools (IZhO13_school)C++14
20 / 100
753 ms28996 KiB
#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 timeMemoryGrader output
Fetching results...