답안 #1112906

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1112906 2024-11-15T08:38:37 Z 0pt1mus23 학교 설립 (IZhO13_school) C++14
100 / 100
82 ms 14464 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define ins insert      
#define pii pair<int,int>
#define pb push_back
#define endl '\n'
#define putr(x) cout<<x<<endl;return; 
#define all(x) x.begin(),x.end()
const int mod = 1e9 +7, sze = 2e5 +23, inf = LLONG_MAX, LG = 20;

void fast(){
    int n,m,s;
    cin>>n>>m>>s;
    vector<pii> arr(n+1);
    for(int i =1;i<=n;i++){
        cin>>arr[i].first>>arr[i].second;
    }
    sort(arr.begin()+1,arr.end(),[&](pii a,pii b){
        return a.second - a.first < b.second - b.first;
    });
    vector<int> pref(n+10,0),suff(n+10,0);

    int ans=0,pf=0;

    priority_queue<int,vector<int>,greater<int>> q;
    for(int i =1;i<=n;i++){
        pf+=arr[i].first;
        q.push(arr[i].first);
        if(q.size()>m){
            pf-=q.top();
            q.pop();
        }
        pref[i]=pf;
    }
    while(!q.empty()) q.pop();
    int sfa =0; 
    for(int i = n;i>=1;i--){
        sfa+=arr[i].second;
        q.push(arr[i].second);
        if(q.size()>s){
            sfa-=q.top();
            q.pop();
        }
        suff[i]=sfa;
    }
    for(int i=1;i<=n;i++){

        ans=max(ans,pref[i]+suff[i+1]);
    }



    putr(ans);
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int tt = 1;

    // cin>>tt;
 
    while(tt--){
        fast();
    }
 
    return 0;
}

Compilation message

school.cpp: In function 'void fast()':
school.cpp:30:20: 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 'long long int' [-Wsign-compare]
   30 |         if(q.size()>m){
      |            ~~~~~~~~^~
school.cpp:41:20: 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 'long long int' [-Wsign-compare]
   41 |         if(q.size()>s){
      |            ~~~~~~~~^~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 336 KB Output is correct
2 Correct 1 ms 336 KB Output is correct
3 Correct 1 ms 336 KB Output is correct
4 Correct 1 ms 336 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
6 Correct 1 ms 336 KB Output is correct
7 Correct 2 ms 592 KB Output is correct
8 Correct 2 ms 592 KB Output is correct
9 Correct 3 ms 592 KB Output is correct
10 Correct 2 ms 592 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 3 ms 592 KB Output is correct
13 Correct 16 ms 2292 KB Output is correct
14 Correct 22 ms 4052 KB Output is correct
15 Correct 36 ms 7256 KB Output is correct
16 Correct 49 ms 11048 KB Output is correct
17 Correct 64 ms 10920 KB Output is correct
18 Correct 80 ms 11780 KB Output is correct
19 Correct 75 ms 12556 KB Output is correct
20 Correct 82 ms 14464 KB Output is correct