Submission #503380

#TimeUsernameProblemLanguageResultExecution timeMemory
503380lukameladzeSchools (IZhO13_school)C++14
100 / 100
233 ms19788 KiB
# include <bits/stdc++.h> #define f first #define s second #define pb push_back #define int long long #define pii pair <int, int> using namespace std; const int N = 3e5 + 5; int n,m,k,a[N],b[N],sum,num,ans,pr[N],sf[N]; multiset <int> ms; multiset <int> :: iterator it; vector <pii> v; main() { std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0); cin>>n>>m>>k; for (int i = 1; i <= n; i++) { cin>>a[i]>>b[i]; v.pb({a[i] - b[i], i}); } sort(v.begin(),v.end()); reverse(v.begin(),v.end()); if (m) { for (int i = 0; i < v.size(); i++) { num = a[v[i].s]; if (ms.size() < m) { ms.insert(num); sum += num; } else { it = ms.begin(); if (*it < num) { sum -= *it; ms.erase(it); sum += num; ms.insert(num); } } pr[i] = sum; } } sum = 0; ms.clear(); if (k) { for (int i = (int)v.size() - 1; i >= 0; i--) { num = b[v[i].s]; if (ms.size() < k) { ms.insert(num); sum += num; } else { it = ms.begin(); if (*it < num) { sum -= *it; ms.erase(it); sum += num; ms.insert(num); } } sf[i] = sum; } } if (m == 0) { cout<<sf[0]<<endl; return 0; } if (k == 0) { cout<<pr[n-1]<<endl; return 0; } for (int i = m - 1; i <= n - k - 1; i++) { ans = max(ans, pr[i] + sf[i + 1]); } cout<<ans<<endl; }

Compilation message (stderr)

school.cpp:13:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   13 | main() {
      | ^~~~
school.cpp: In function 'int main()':
school.cpp:22:27: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   22 |         for (int i = 0; i < v.size(); i++) {
      |                         ~~^~~~~~~~~~
school.cpp:24:27: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   24 |             if (ms.size() < m) {
      |                 ~~~~~~~~~~^~~
school.cpp:44:27: warning: comparison of integer expressions of different signedness: 'std::multiset<long long int>::size_type' {aka 'long unsigned int'} and 'long long int' [-Wsign-compare]
   44 |             if (ms.size() < k) {
      |                 ~~~~~~~~~~^~~
#Verdict Execution timeMemoryGrader output
Fetching results...