답안 #676386

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
676386 2022-12-30T15:11:17 Z vjudge1 학교 설립 (IZhO13_school) C++17
100 / 100
112 ms 10828 KB
#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;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 328 KB Output is correct
4 Correct 0 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 15 ms 1996 KB Output is correct
14 Correct 36 ms 3544 KB Output is correct
15 Correct 68 ms 6476 KB Output is correct
16 Correct 70 ms 7756 KB Output is correct
17 Correct 84 ms 8580 KB Output is correct
18 Correct 98 ms 9196 KB Output is correct
19 Correct 102 ms 9676 KB Output is correct
20 Correct 112 ms 10828 KB Output is correct