답안 #210609

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
210609 2020-03-17T20:38:56 Z mohamedsobhi777 학교 설립 (IZhO13_school) C++14
100 / 100
326 ms 16476 KB
#include <bits/stdc++.h> 


using namespace std ;
const int N = 3e5 +5 ; 

int n , M , S; 
vector<pair<int , int > > v; 
long long m[N] , s[N] ; 
long long pre[N] , suf[N] ;
long long sum  , sol; 

int main(){
    cin>>n>>M>>S; 
    for(int i = 0 ; i < n ; i++){
        cin>>m[i]>>s[i] ; 
        v.push_back({s[i]-m[i] , i}) ;
    }    
    sort(v.begin() , v.end());
    priority_queue<int , vector<int> , greater<int>  > q ; 
    for(int i = 0 ; i <n ; i++){
        if(q.size()< M){
            sum+=m[v[i].second] ;
            q.push(m[v[i].second]);
        }else if( q.top() < m[v[i].second] ){
            sum+= m[v[i].second] - q.top(); 
            q.pop();
            q.push(m[v[i].second]);            
        }
        pre[i] = sum ; 
    }
    while(q.size() )q.pop() ; sum = 0;
    for(int i = n-1 ; i>= 0 ; i--){
        if(q.size() < S ) {
            sum+=s[v[i].second] ; 
            q.push(s[v[i].second]) ; 
        }
        else if(q.top() < s[v[i].second]) {
            sum+=s[v[i].second] - q.top() ; 
            q.pop() ; 
            q.push(s[v[i].second]) ; 
        }
        suf[i] = sum; 
    }
    sol = suf[0] ; 
    for(int i = 0 ; i <n ; i++){
        sol = max(sol , pre[i] + suf[i+1]) ; 
    }
    cout<<sol;
    return 0 ; 
}

Compilation message

school.cpp: In function 'int main()':
school.cpp:22:20: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(q.size()< M){
            ~~~~~~~~^~~
school.cpp:32:5: warning: this 'while' clause does not guard... [-Wmisleading-indentation]
     while(q.size() )q.pop() ; sum = 0;
     ^~~~~
school.cpp:32:31: note: ...this statement, but the latter is misleadingly indented as if it were guarded by the 'while'
     while(q.size() )q.pop() ; sum = 0;
                               ^~~
school.cpp:34:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(q.size() < S ) {
            ~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 376 KB Output is correct
2 Correct 5 ms 376 KB Output is correct
3 Correct 5 ms 376 KB Output is correct
4 Correct 5 ms 376 KB Output is correct
5 Correct 5 ms 376 KB Output is correct
6 Correct 5 ms 376 KB Output is correct
7 Correct 9 ms 632 KB Output is correct
8 Correct 9 ms 760 KB Output is correct
9 Correct 9 ms 632 KB Output is correct
10 Correct 9 ms 632 KB Output is correct
11 Correct 9 ms 632 KB Output is correct
12 Correct 9 ms 608 KB Output is correct
13 Correct 42 ms 2412 KB Output is correct
14 Correct 81 ms 4456 KB Output is correct
15 Correct 153 ms 8420 KB Output is correct
16 Correct 189 ms 10980 KB Output is correct
17 Correct 259 ms 12388 KB Output is correct
18 Correct 262 ms 13540 KB Output is correct
19 Correct 285 ms 14436 KB Output is correct
20 Correct 326 ms 16476 KB Output is correct