답안 #49681

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
49681 2018-06-02T05:32:34 Z mra2322001 학교 설립 (IZhO13_school) C++14
100 / 100
131 ms 25632 KB
#include <bits/stdc++.h>
#define f0(i, n) for(int i(0); i<(n); i++)
#define f1(i, n) for(int i(1); i<=(n); i++)

using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
const int N = 300002;

int n, s, t;
long t1[N], t2[N];
pii a[N];

istream& operator >> (istream &is, pii &iu){
    cin >> iu.first >> iu.second;
}

int main(){
    ios_base::sync_with_stdio(0);
  
    cin >> n >> s >> t;
    f1(i, n) cin >> a[i];
    sort(a + 1, a + n + 1, [&](pii a1, pii a2){
         return (a1.second - a1.first) < (a2.second - a2.first);
    });
    priority_queue <int, vector <int>, greater <int> > q;
    f1(i, n){
        if(q.size() < s){
            t1[i] = t1[i - 1] + a[i].first;
            q.push(a[i].first);
        }
        else if(q.top() < a[i].first){
            t1[i] = t1[i - 1] - q.top() + a[i].first;
            q.pop();
            q.push(a[i].first);
        }
        else{
            t1[i] = t1[i - 1];
        }
    }
    while(q.size()) q.pop();
    for(int i = n; i >= 1; i--){
        if(q.size() < t){
            t2[i] = t2[i + 1] + a[i].second;
            q.push(a[i].second);
        }
        else if(q.top() < a[i].second){
            t2[i] = t2[i + 1] - q.top() + a[i].second;
            q.pop();
            q.push(a[i].second);
        }
        else{
            t2[i] = t2[i + 1];
        }
    }
    long res = 0;
    f1(i, n){
        if(i >= s && (n - i) >= t) res = max(res, t1[i] + t2[i + 1]);
    }
    cout << res;
}

Compilation message

school.cpp: In function 'std::istream& operator>>(std::istream&, pii&)':
school.cpp:16:1: warning: no return statement in function returning non-void [-Wreturn-type]
 }
 ^
school.cpp: In function 'int main()':
school.cpp:28:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(q.size() < s){
            ~~~~~~~~~^~~
school.cpp:43:21: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
         if(q.size() < t){
            ~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 3 ms 376 KB Output is correct
3 Correct 2 ms 416 KB Output is correct
4 Correct 2 ms 436 KB Output is correct
5 Correct 2 ms 484 KB Output is correct
6 Correct 2 ms 616 KB Output is correct
7 Correct 5 ms 712 KB Output is correct
8 Correct 5 ms 944 KB Output is correct
9 Correct 6 ms 944 KB Output is correct
10 Correct 5 ms 1092 KB Output is correct
11 Correct 4 ms 1092 KB Output is correct
12 Correct 5 ms 1096 KB Output is correct
13 Correct 20 ms 2448 KB Output is correct
14 Correct 36 ms 4384 KB Output is correct
15 Correct 54 ms 7936 KB Output is correct
16 Correct 70 ms 11148 KB Output is correct
17 Correct 92 ms 14304 KB Output is correct
18 Correct 98 ms 17672 KB Output is correct
19 Correct 106 ms 21288 KB Output is correct
20 Correct 131 ms 25632 KB Output is correct