Submission #676304

#TimeUsernameProblemLanguageResultExecution timeMemory
676304vjudge1Schools (IZhO13_school)C++17
5 / 100
204 ms13868 KiB
#include <bits/stdc++.h> using namespace std; const int N = 3e5 + 5; /* i < j a[i] + b[j] > a[j] + b[i] <=> a[i] - a[j] > b[i] - b[j] --> just choose prefix */ int id[N]; int a[N], b[N]; int n, m, s; int64_t pre[N], suf[N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> n >> m >> s; for (int i = 1; i <= n; i++) { cin >> a[i] >> b[i]; } sort(id + 1, id + n + 1, [&](int i, int j) { return a[i] - a[j] > b[i] - b[j]; }); { multiset<int> ss; int64_t cur = 0; for (int i = 1; i <= n; i++) { cur += a[i]; ss.insert(a[i]); if (ss.size() > m) { cur -= *ss.begin(); ss.erase(*ss.begin()); } pre[i] = cur; } } { multiset<int> ss; int64_t cur = 0; for (int i = n; i >= 1; i--) { cur += b[i]; ss.insert(b[i]); if (ss.size() > s) { cur -= *ss.begin(); ss.erase(*ss.begin()); } suf[i] = cur; } } int64_t best = 0; for (int i = m; i <= n - s; i++) { best = max(best, pre[i] + suf[i + 1]); } cout << best; return 0; }

Compilation message (stderr)

school.cpp: In function 'int main()':
school.cpp:38:21: warning: comparison of integer expressions of different signedness: 'std::multiset<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   38 |       if (ss.size() > m) {
      |           ~~~~~~~~~~^~~
school.cpp:52:21: warning: comparison of integer expressions of different signedness: 'std::multiset<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   52 |       if (ss.size() > s) {
      |           ~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...