#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
#include <bits/stdc++.h>
using namespace std;
bool comp(pair<int,int>a,pair<int,int>b){
return (a.first-a.second)>(b.first-b.second);
}
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int n,s,m;
cin>>n>>s>>m;
vector<pair<long long,long long>>v;
for(int i = 0;i<n;i++){
long long a,b;
cin>>a>>b;
v.push_back({a,b});
}
sort(v.begin(),v.end(),comp);
priority_queue<long long> p1,p2;
long long sum = 0,sum2 = 0;
long long pref[n+2] = {0},suf[n+2]= {0};
for(int i= 1;i<=n;i++){
p1.push(-v[i-1].first);
if(p1.size()>s){sum+=p1.top();p1.pop();}
sum+=v[i-1].first;
pref[i]=sum;
}
for(int i= n;i>=1;i--){
p2.push(-v[i-1].second);
if(p2.size()>m){sum2+=p2.top();p2.pop();}
sum2+=v[i-1].second;
suf[i]= sum2;
}
cout<<endl;
long long ans = -1e18;
for(int i = 0;i<=n;i++){
ans = max(ans,pref[i]+suf[i+1]);
}
cout<<ans<<endl;
}
Compilation message
school.cpp: In function 'int main()':
school.cpp:24:21: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
24 | if(p1.size()>s){sum+=p1.top();p1.pop();}
| ~~~~~~~~~^~
school.cpp:30:21: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int>::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
30 | if(p2.size()>m){sum2+=p2.top();p2.pop();}
| ~~~~~~~~~^~
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
316 KB |
Output is correct |
4 |
Correct |
1 ms |
212 KB |
Output is correct |
5 |
Correct |
1 ms |
340 KB |
Output is correct |
6 |
Correct |
1 ms |
320 KB |
Output is correct |
7 |
Correct |
3 ms |
592 KB |
Output is correct |
8 |
Correct |
2 ms |
596 KB |
Output is correct |
9 |
Correct |
2 ms |
596 KB |
Output is correct |
10 |
Correct |
2 ms |
596 KB |
Output is correct |
11 |
Correct |
2 ms |
596 KB |
Output is correct |
12 |
Correct |
2 ms |
584 KB |
Output is correct |
13 |
Correct |
13 ms |
2252 KB |
Output is correct |
14 |
Correct |
29 ms |
4088 KB |
Output is correct |
15 |
Correct |
55 ms |
7120 KB |
Output is correct |
16 |
Correct |
70 ms |
11396 KB |
Output is correct |
17 |
Correct |
79 ms |
12292 KB |
Output is correct |
18 |
Correct |
90 ms |
13048 KB |
Output is correct |
19 |
Correct |
95 ms |
13952 KB |
Output is correct |
20 |
Correct |
110 ms |
15860 KB |
Output is correct |