제출 #1327474

#제출 시각아이디문제언어결과실행 시간메모리
1327474deh학교 설립 (IZhO13_school)C++20
100 / 100
120 ms11812 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) 메시지

school.cpp: In function 'int main()':
school.cpp:56:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   56 |         freopen("deH.INP","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~
school.cpp:57:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   57 |         freopen("deH.OUT","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...