Submission #47526

#TimeUsernameProblemLanguageResultExecution timeMemory
47526aomeSchools (IZhO13_school)C++17
100 / 100
191 ms9476 KiB
#include <bits/stdc++.h> using namespace std; const int N = 300005; int n, m, q, a[N], b[N], p[N]; long long f[N], g[N], s, res; bool cmp(int x, int y) { return a[x] - b[x] < a[y] - b[y]; } int main() { ios::sync_with_stdio(false); cin >> n >> m >> q; for (int i = 0; i < n; ++i) cin >> a[i] >> b[i]; for (int i = 0; i < n; ++i) p[i] = i; sort(p, p + n, cmp); priority_queue<int> pq; s = 0; for (int i = 0; i < n; ++i) { pq.push(-b[p[i]]); s += b[p[i]]; if (pq.size() > q) { s += pq.top(); pq.pop(); } f[i] = s; } while (pq.size()) pq.pop(); s = 0; for (int i = n - 1; i >= 0; --i) { pq.push(-a[p[i]]); s += a[p[i]]; if (pq.size() > m) { s += pq.top(); pq.pop(); } g[i] = s; } for (int i = q - 1; i < n - m; ++i) res = max(res, f[i] + g[i + 1]); cout << res; }

Compilation message (stderr)

school.cpp: In function 'int main()':
school.cpp:23:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (pq.size() > q) {
             ~~~~~~~~~~^~~
school.cpp:32:23: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if (pq.size() > m) {
             ~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...