# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
84475 | hamzqq9 | 학교 설립 (IZhO13_school) | C++14 | 189 ms | 11704 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)>>1)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define inf 2005000000
#define MOD 1000000007
#define N 300005
#define M 1000005
#define LOG 18
#define KOK 4000000
using namespace std;
int n,m,s;
int a[N],b[N],plc[N];
ll pre[N],suf[N];
ll ans;
priority_queue<int> q;
void up(int now) {
if(sz(q)<m) {
ans+=a[now];
q.push(-a[now]);
}
else {
int val=q.top();
if(val+a[now]>0) {
ans+=val+a[now];
q.pop();
q.push(-a[now]);
}
}
}
int main() {
// freopen("input.txt","r",stdin);
scanf("%d %d %d",&n,&m,&s);
for(int i=1;i<=n;i++) {
scanf("%d %d",&a[i],&b[i]);
plc[i]=i;
}
sort(plc+1,plc+1+n,[](int x,int y) {
if(a[x]-b[x]==a[y]-b[y]) return a[x]>a[y];
return a[x]-b[x]>a[y]-b[y];
});
for(int i=1;i<=n;i++) {
up(plc[i]);
pre[i]=ans;
swap(a[plc[i]],b[plc[i]]);
}
ans=0;
while(sz(q)) q.pop();
swap(m,s);
for(int i=n;i>=1;i--) {
up(plc[i]);
suf[i]=ans;
}
swap(m,s);
ans=0;
for(int i=m;i<=n-s;i++) {
umax(ans,pre[i]+suf[i+1]);
}
printf("%lld",ans);
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |