# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
676386 | vjudge1 | 학교 설립 (IZhO13_school) | C++17 | 112 ms | 10828 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int MAXN=3e5;
int n, m, s;
int a[MAXN+5];
int b[MAXN+5];
int id[MAXN+5];
bool cmp(int i, int j){
return a[i]-b[i]>a[j]-b[j];
}
ll pre[MAXN+5];
ll suf[MAXN+5];
priority_queue<int, vector<int>, greater<int> > pq;
int main(){
// freopen("C.INP", "r", stdin);
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
cin>>n>>m>>s;
for(int i=1; i<=n; i++){
cin>>a[i]>>b[i];
id[i]=i;
}
sort(id+1, id+n+1, cmp);
ll cur=0;
for(int i=1; i<=n; i++){
pq.push(a[id[i]]);
cur+=a[id[i]];
if(i>m){
cur-=pq.top();
pq.pop();
}
pre[i]=cur;
}
cur=0;
while(!pq.empty()) pq.pop();
for(int i=n; i>=1; i--){
pq.push(b[id[i]]);
cur+=b[id[i]];
if(i<n-s+1){
cur-=pq.top();
pq.pop();
}
suf[i]=cur;
}
ll res=0;
for(int i=m; i+s<=n; i++){
res=max(res, suf[i+1]+pre[i]);
}
cout<<res;
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |