답안 #83707

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
83707 2018-11-10T03:31:17 Z mra2322001 학교 설립 (IZhO13_school) C++14
20 / 100
127 ms 27084 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;
const int N = 300002;

int n, m, s;
ll ans1[N], ans2[N];
pair <int, int> a[N];

int main(){
    ios_base::sync_with_stdio(0);

    cin >> n >> m >> s;
    f1(i, n) cin >> a[i].first >> a[i].second;

    sort(a + 1, a + n + 1, [&](pair <int, int> a1, pair <int, int> a2){
         return a1.first - a1.second > a2.first - a2.second;
    });

    priority_queue <int, vector <int>, greater <int> > q;
    if(m > 0){
        f1(i, n){
            if(i <= m){
                ans1[i] = ans1[i - 1] + a[i].first;
                q.push(a[i].first);
            }
            else{
                ans1[i] = max(ans1[i - 1] - q.top() + a[i].first, ans1[i - 1]);
                if(q.top() <= a[i].first){
                    q.pop();
                    q.push(a[i].first);
                }
            }
        }
    }
    while(q.size()) q.pop();
    if(s){
        for(int i = n; i >= 1; i--){
            if(n - i + 1 <= s){
                ans2[i] = ans2[i + 1] +a[i].second;
            }
            else{
                ans2[i] = max(ans2[i + 1], ans2[i + 1] - q.top() + a[i].second);
                if(ans2[i] != ans2[i + 1]){
                    q.pop();
                    q.push(a[i].second);
                }
            }
        }
    }
    ll ans = 0;
    f0(i, n + 1){
        if(i >= m && n - i >= s) ans = max(ans, ans1[i] + ans2[i + 1]);
    }
    cout << ans;
}

# 결과 실행 시간 메모리 Grader output
1 Correct 2 ms 504 KB Output is correct
2 Correct 2 ms 616 KB Output is correct
3 Correct 2 ms 660 KB Output is correct
4 Incorrect 2 ms 748 KB Output isn't correct
5 Incorrect 2 ms 856 KB Output isn't correct
6 Incorrect 2 ms 856 KB Output isn't correct
7 Incorrect 3 ms 896 KB Output isn't correct
8 Runtime error 9 ms 1672 KB Execution killed with signal 11 (could be triggered by violating memory limits)
9 Runtime error 7 ms 1828 KB Execution killed with signal 11 (could be triggered by violating memory limits)
10 Runtime error 7 ms 1828 KB Execution killed with signal 11 (could be triggered by violating memory limits)
11 Incorrect 4 ms 1828 KB Output isn't correct
12 Incorrect 4 ms 1828 KB Output isn't correct
13 Runtime error 23 ms 4248 KB Execution killed with signal 11 (could be triggered by violating memory limits)
14 Incorrect 36 ms 5764 KB Output isn't correct
15 Incorrect 54 ms 9364 KB Output isn't correct
16 Correct 127 ms 12068 KB Output is correct
17 Incorrect 99 ms 15712 KB Output isn't correct
18 Incorrect 98 ms 19172 KB Output isn't correct
19 Incorrect 110 ms 22628 KB Output isn't correct
20 Incorrect 122 ms 27084 KB Output isn't correct