Submission #164415

#TimeUsernameProblemLanguageResultExecution timeMemory
164415tselmegkhSchools (IZhO13_school)C++14
100 / 100
540 ms14276 KiB
#include<bits/stdc++.h> using namespace std; const int N = 3e5 + 5; long long sum[N][2]; int main(){ int n, m, s; cin >> n >> m >> s; vector<pair<int, pair<int, int>>> v1; for(int i = 0; i < n; i++){ int a, b; cin >> a >> b; v1.push_back({a - b, {a, b}}); } sort(v1.rbegin(), v1.rend()); long long tot = 0; multiset<long long> ms; for(int i = 0; i < n; i++){ ms.insert(v1[i].second.first); tot += v1[i].second.first; if(ms.size() > m){ tot -= *ms.begin(); ms.erase(ms.begin()); } sum[i + 1][0] = tot; } tot = 0; ms.clear(); for(int i = n - 1; i >= 0; i--){ ms.insert(v1[i].second.second); tot += v1[i].second.second; if(ms.size() > s){ tot -= *ms.begin(); ms.erase(ms.begin()); } sum[i + 1][1] = tot; } long long ans = 0; for(int i = m; i <= n - s; i++){ ans = max(ans, sum[i][0] + sum[i + 1][1]); } cout << ans << '\n'; }

Compilation message (stderr)

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