답안 #499135

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
499135 2021-12-27T09:39:35 Z infertechno2 학교 설립 (IZhO13_school) C++17
100 / 100
110 ms 14128 KB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const ll Size=3e5+10;
pair<ll,ll> a[Size];
ll ansm[Size],anss[Size];

bool comp(const pair<ll,ll>& A,const pair<ll,ll>& B){
    return (A.first-A.second)<(B.first-B.second);
}

void solve(){
    ll n,m,s;
    cin>>n>>m>>s;
    for(ll i=1;i<=n;i++){
        cin>>a[i].first>>a[i].second;
    }
    sort(a+1,a+n+1,comp);
    priority_queue<ll,vector<ll>,greater<ll>> to_remove;
    ll ans_for_s=0;
    for(ll i=1;i<=n;i++){
        to_remove.push(a[i].second);
        ans_for_s+=a[i].second;
        if(to_remove.size()>s){
            ans_for_s-=to_remove.top();
            to_remove.pop();
        }
        anss[i]=ans_for_s;
    }
    while(!to_remove.empty()){
        to_remove.pop();
    }
    ll ans_for_m=0;
    for(ll i=n;i>0;i--){
        to_remove.push(a[i].first);
        ans_for_m+=a[i].first;
        if(to_remove.size()>m){
            ans_for_m-=to_remove.top();
            to_remove.pop();
        }
        ansm[i]=ans_for_m;
    }
    ll ans=0;
    for(ll i=0;i<=n;i++){
        ans=max(ans,anss[i]+ansm[i+1]);
    }
    cout<<ans<<endl;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll t=1;
    while(t--){
        solve();
    }
    return 0;
}

Compilation message

school.cpp: In function 'void solve()':
school.cpp:27:28: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int, std::vector<long long int>, std::greater<long long int> >::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   27 |         if(to_remove.size()>s){
      |            ~~~~~~~~~~~~~~~~^~
school.cpp:40:28: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long long int, std::vector<long long int>, std::greater<long long int> >::size_type' {aka 'long unsigned int'} and 'll' {aka 'long long int'} [-Wsign-compare]
   40 |         if(to_remove.size()>m){
      |            ~~~~~~~~~~~~~~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 0 ms 328 KB Output is correct
3 Correct 0 ms 320 KB Output is correct
4 Correct 0 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 0 ms 320 KB Output is correct
7 Correct 2 ms 524 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 2 ms 608 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 11 ms 2132 KB Output is correct
14 Correct 29 ms 3948 KB Output is correct
15 Correct 49 ms 7112 KB Output is correct
16 Correct 79 ms 9384 KB Output is correct
17 Correct 82 ms 10668 KB Output is correct
18 Correct 93 ms 11452 KB Output is correct
19 Correct 95 ms 12304 KB Output is correct
20 Correct 110 ms 14128 KB Output is correct