답안 #673599

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
673599 2022-12-21T09:13:23 Z moday_morning 학교 설립 (IZhO13_school) C++17
100 / 100
131 ms 10772 KB
#include <bits/stdc++.h>
#define fr first
#define sc second
#define int long long
using namespace std;

const int N = 300005;
int v[N], v1[N];
pair <int, int> a[N];

void solve () {
    int n, x, y;
    cin >> n >> x >> y;
    for(int i = 1; i <= n; i++) {
        cin >> a[i].fr >> a[i].sc;
    }
    sort(a+1, a+n+1, [] (pair <int, int> a, pair <int, int> b) -> bool {return a.fr - a.sc > b.fr - b.sc;});
    priority_queue<int, vector<int>, greater<int>> q;
    int sum = 0;;
    for (int i = 1; i <= n; i++) {
        sum += a[i].fr;
        q.push(a[i].fr);
        if(q.size() > x) {
            sum -= q.top();
            q.pop();
        }
        v[i] = sum;
    }
    while (!q.empty()) {
        q.pop();
        sum = 0;
    }
    for (int i = n; i >= 1; i--) {
        sum += a[i].sc;
        q.push(a[i].sc);
        if (q.size() > y) {
            sum -= q.top();
            q.pop();
        }
        v1[i] = sum;
    }
    int mx = 0;
    for (int i = x; i <= n-y; i++) {
        mx = max(mx, v[i] + v1[i+1]);
    }
    cout << mx << "\n";
}

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
//    cin >> t;
    while (t--) {
        solve();
    }
}

Compilation message

school.cpp: In function 'void solve()':
school.cpp:23:21: 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]
   23 |         if(q.size() > x) {
      |            ~~~~~~~~~^~~
school.cpp:36:22: 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]
   36 |         if (q.size() > y) {
      |             ~~~~~~~~~^~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 340 KB Output is correct
2 Correct 1 ms 328 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 2 ms 596 KB Output is correct
9 Correct 2 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 2 ms 592 KB Output is correct
12 Correct 2 ms 596 KB Output is correct
13 Correct 14 ms 1944 KB Output is correct
14 Correct 26 ms 3152 KB Output is correct
15 Correct 54 ms 5496 KB Output is correct
16 Correct 58 ms 7880 KB Output is correct
17 Correct 79 ms 8232 KB Output is correct
18 Correct 82 ms 8760 KB Output is correct
19 Correct 91 ms 9416 KB Output is correct
20 Correct 131 ms 10772 KB Output is correct