| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1327474 | deh | 학교 설립 (IZhO13_school) | C++20 | 120 ms | 11812 KiB |
#include <bits/stdc++.h>
#define ll long long
#define f first
#define s second
const ll oo = -4000000000000000000;
using namespace std;
int n,x,y;
ll a[300005],b[300005];
bool cmp(int x,int y){
return (a[x]-b[x]) > (a[y]-b[y]);
}
ll pre[300005],suf[300005];
int v[300005];
void solve(){
cin >> n >> x >> y;
for(int i = 1;i <= n;i++){
cin >> a[i] >> b[i];
v[i] = i;
}
sort(v+1,v+n+1,cmp);
priority_queue<ll,vector<ll>,greater<ll>> pq;
ll sum = 0;
for(int t = 1;t <= n;t++){
int i = v[t];
ll g = a[i];
pq.push(g);
sum += g;
if(pq.size() > x){
sum -= pq.top();
pq.pop();
}
pre[t] = sum;
}
while(pq.size() != 0)pq.pop();
sum = 0;
for(int t = n;t >= 1;t--){
int i = v[t];
ll g = b[i];
pq.push(g);
sum += g;
if(pq.size() > y){
sum -= pq.top();
pq.pop();
}
suf[t] = sum;
}
ll res = LLONG_MIN;
for(int i = 0;i <= n;i++){
res = max(res,pre[i]+suf[i+1]);
}
cout << res;
}
int main(){
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
if(fopen("deH.INP","r")){
freopen("deH.INP","r",stdin);
freopen("deH.OUT","w",stdout);
}
int ts = 1;//cin >> ts;
while(ts--)solve();
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
| # | Verdict | Execution time | Memory | Grader output |
|---|---|---|---|---|
| Fetching results... | ||||
