Submission #377365

#TimeUsernameProblemLanguageResultExecution timeMemory
377365ijxjdjdSchools (IZhO13_school)C++14
100 / 100
230 ms18668 KiB
#include <bits/stdc++.h> #define FR(i, N) for (int i = 0; i < int(N); i++) #define all(x) begin(x), end(x) using namespace std; using ll = long long; int main() { cin.tie(0); cin.sync_with_stdio(0); int N; int M, S; cin >> N >> M >> S; vector<pair<ll, ll>> vec(N); FR(i, N) { cin >> vec[i].first >> vec[i].second; } sort(all(vec), [](const auto& lhs, const auto& rhs) { return lhs.first - lhs.second > rhs.first - rhs.second; }); vector<ll> suf(N); vector<ll> pref(N); multiset<int> mx; ll sm = 0; for (int i = N-1; i >= 0; i--) { mx.insert(vec[i].second); sm += vec[i].second; if (mx.size() > S) { sm -= *mx.begin(); mx.erase(mx.begin()); } suf[i] = sm; } mx.clear(); sm = 0; for (int i = 0; i < N; i++) { mx.insert(vec[i].first); sm += vec[i].first; if (mx.size() > M) { sm -= *mx.begin(); mx.erase(mx.begin()); } pref[i] = sm; } ll ans = max(suf[0], pref[N-1]); for (int i = 0; i + 1 < N; i++) { ans = max(pref[i] + suf[i+1], ans); } cout << ans << '\n'; return 0; }

Compilation message (stderr)

school.cpp: In function 'int main()':
school.cpp:29:23: warning: comparison of integer expressions of different signedness: 'std::multiset<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   29 |         if (mx.size() > S) {
      |             ~~~~~~~~~~^~~
school.cpp:40:23: warning: comparison of integer expressions of different signedness: 'std::multiset<int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   40 |         if (mx.size() > M) {
      |             ~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...