# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
286280 | 2020-08-30T09:07:06 Z | shrek12357 | Schools (IZhO13_school) | C++14 | 136 ms | 14944 KB |
#include <bits/stdc++.h> using namespace std ; const int MAX = 300000 + 10 ; long long M[MAX] , S[MAX] ; long long prefM[MAX] , suffS[MAX] ; int n , m , s ; int main() { ios_base::sync_with_stdio(0) ; cin.tie(0) ; cin>>n>>m>>s ; vector< pair<int , int> >vp ; for(int i = 0 ; i < n ; ++i) { cin>>M[i]>>S[i] ; vp.push_back({M[i]-S[i] , i}) ; } sort(vp.rbegin() , vp.rend()) ; priority_queue< long long , vector<long long> , greater<long long> >q ; long long sum = 0 ; for(int i = 0 ; i < n ; ++i) { int idx = vp[i].second ; if(q.size() < m) { sum += M[idx] ; q.push(M[idx]) ; } else if(q.top() < M[idx]) { sum -= q.top() ; q.pop() ; sum += M[idx] ; q.push(M[idx]) ; } prefM[i] = sum ; } while(q.size() > 0) q.pop() ; sum = 0 ; for(int i = n-1 ; i >= 0 ; --i) { int idx = vp[i].second ; if(q.size() < s) { sum += S[idx] ; q.push(S[idx]) ; } else if(q.top() < S[idx]) { sum -= q.top() ; q.pop() ; sum += S[idx] ; q.push(S[idx]) ; } suffS[i] = sum ; } long long ans = suffS[0] ; for(int i = 0 ; i < n ; ++i) ans = max(ans , prefM[i] + suffS[i+1]) ; return cout<<ans<<"\n" , 0 ; }
Compilation message
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
1 | Correct | 0 ms | 384 KB | Output is correct |
2 | Correct | 0 ms | 384 KB | Output is correct |
3 | Correct | 0 ms | 384 KB | Output is correct |
4 | Correct | 0 ms | 384 KB | Output is correct |
5 | Correct | 0 ms | 384 KB | Output is correct |
6 | Correct | 1 ms | 384 KB | Output is correct |
7 | Correct | 2 ms | 660 KB | Output is correct |
8 | Correct | 2 ms | 640 KB | Output is correct |
9 | Correct | 3 ms | 640 KB | Output is correct |
10 | Correct | 2 ms | 640 KB | Output is correct |
11 | Correct | 2 ms | 640 KB | Output is correct |
12 | Correct | 2 ms | 640 KB | Output is correct |
13 | Correct | 18 ms | 2676 KB | Output is correct |
14 | Correct | 30 ms | 4336 KB | Output is correct |
15 | Correct | 53 ms | 7272 KB | Output is correct |
16 | Correct | 74 ms | 10600 KB | Output is correct |
17 | Correct | 101 ms | 11752 KB | Output is correct |
18 | Correct | 108 ms | 12484 KB | Output is correct |
19 | Correct | 116 ms | 13404 KB | Output is correct |
20 | Correct | 136 ms | 14944 KB | Output is correct |