답안 #972667

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
972667 2024-04-30T20:41:49 Z imarn 학교 설립 (IZhO13_school) C++14
100 / 100
105 ms 11468 KB
#include<bits/stdc++.h>
#define f first
#define s second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define sz(x) (ll)x.size()
using namespace std;
bool cmp(pii a,pii b){
    return a.f-a.s>b.f-b.s;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int n,m,s;cin>>n>>m>>s;pii a[n+1];
    for(int i=1;i<=n;i++)cin>>a[i].f>>a[i].s;
    sort(a+1,a+n+1,cmp);
    ll dl[n+2]={0},dr[n+2]={0},sum=0;
    priority_queue<int,vector<int>,greater<int>>q;
    for(int i=1;i<=n;i++){
        sum+=a[i].f;q.push(a[i].f);
        while(!q.empty()&&q.size()>m)sum-=q.top(),q.pop();
        dl[i]=sum;
    }sum=0;while(!q.empty())q.pop();
    for(int i=n;i>=1;i--){
        sum+=a[i].s;q.push(a[i].s);
        while(!q.empty()&&q.size()>s)sum-=q.top(),q.pop();
        dr[i]=sum;
    }ll ans=0;
    for(int i=0;i<=n;i++)if(i>=m&&n-i>=s)ans=max(ans,dl[i]+dr[i+1]);
    cout<<ans;
}

Compilation message

school.cpp: In function 'int main()':
school.cpp:21:35: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   21 |         while(!q.empty()&&q.size()>m)sum-=q.top(),q.pop();
      |                           ~~~~~~~~^~
school.cpp:26:35: warning: comparison of integer expressions of different signedness: 'std::priority_queue<int, std::vector<int>, std::greater<int> >::size_type' {aka 'long unsigned int'} and 'int' [-Wsign-compare]
   26 |         while(!q.empty()&&q.size()>s)sum-=q.top(),q.pop();
      |                                   ^
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 0 ms 456 KB Output is correct
7 Correct 2 ms 604 KB Output is correct
8 Correct 2 ms 644 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 628 KB Output is correct
11 Correct 2 ms 756 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 13 ms 1880 KB Output is correct
14 Correct 25 ms 3164 KB Output is correct
15 Correct 45 ms 5748 KB Output is correct
16 Correct 57 ms 7636 KB Output is correct
17 Correct 73 ms 8664 KB Output is correct
18 Correct 86 ms 9428 KB Output is correct
19 Correct 88 ms 10196 KB Output is correct
20 Correct 105 ms 11468 KB Output is correct