Submission #445179

#TimeUsernameProblemLanguageResultExecution timeMemory
445179ritul_kr_singhSchools (IZhO13_school)C++17
100 / 100
122 ms6740 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define sp << ' ' << #define nl << '\n' int n, m, s, sum, ans; signed main(){ cin.tie(0)->sync_with_stdio(0); cin >> n >> m >> s; array<int, 2> a[n]; for(auto &i : a) cin >> i[0] >> i[1]; sort(a, a+n, [&](auto &i, auto &j){ return i[0] - i[1] < j[0] - j[1]; }); priority_queue<int> q; for(int i=0; i<n; ++i){ q.push(-a[i][1]); sum += a[i][1]; while((int)q.size() > s) sum += q.top(), q.pop(); a[i][1] = sum; } priority_queue<int> ().swap(q); sum = 0; for(int i=n; --i>=0; ){ q.push(-a[i][0]); sum += a[i][0]; while((int)q.size() > m) sum += q.top(), q.pop(); ans = max(ans, sum + (i ? a[i-1][1] : 0LL)); } cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...