Submission #676298

# Submission time Handle Problem Language Result Execution time Memory
676298 2022-12-30T08:30:31 Z vjudge1 Schools (IZhO13_school) C++17
100 / 100
125 ms 8992 KB
#include <bits/stdc++.h>
using namespace std;


#define f first
#define s second
#define NMAX 300000
typedef long long ll;
int n, M, S;
pair<ll, ll> arr[NMAX + 10];
ll pre[NMAX + 10], sur[NMAX + 10];
priority_queue <ll, vector<ll>, greater<ll> > pq;
bool comp(pair<ll, ll> &u, pair<ll, ll> &v) {
    return (u.f - u.s < v.f - v.s);
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    if(fopen("hth.inp", "r")) {
        freopen("hth.inp", "r", stdin);
        freopen("hth.out", "w", stdout);
    }
    cin >> n >> M >> S;
    for(int i = 1; i <= n; i++) {
        cin >> arr[i].f >> arr[i].s;
    }
    sort(arr + 1, arr + 1 + n, comp);
    long long sum = 0;
    for(int i = 1; i <= S; i++) {
        sum += arr[i].s;
        pq.push(arr[i].s);
    }
    pre[S] = sum;
    for(int i = S + 1; i <= n; i++) {
        pq.push(arr[i].s);
        sum += arr[i].s;
        sum -= pq.top();
        pq.pop();
        pre[i] = sum;
    }
    while(pq.size())
        pq.pop();
    sum = 0;
    for(int i = n; i >= n - M + 1; i --) {
        sum += arr[i].f;
        pq.push(arr[i].f);
    }
    sur[n - M + 1] = sum;
    for(int i = n - M; i > 0; i--) {
        pq.push(arr[i].f);
        sum += arr[i].f;
        sum -= pq.top();
        pq.pop();
        sur[i] = sum;
    }
    ll MAX = 0;
    for(int i = S; i <= n - M; i++)
        MAX = max(MAX, pre[i] + sur[i + 1]);
    cout << MAX;
}

Compilation message

school.cpp: In function 'int main()':
school.cpp:20:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |         freopen("hth.inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
school.cpp:21:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   21 |         freopen("hth.out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 212 KB Output is correct
2 Correct 1 ms 340 KB Output is correct
3 Correct 1 ms 212 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 2 ms 468 KB Output is correct
8 Correct 3 ms 468 KB Output is correct
9 Correct 2 ms 468 KB Output is correct
10 Correct 2 ms 468 KB Output is correct
11 Correct 2 ms 468 KB Output is correct
12 Correct 2 ms 468 KB Output is correct
13 Correct 11 ms 1540 KB Output is correct
14 Correct 31 ms 2788 KB Output is correct
15 Correct 54 ms 5300 KB Output is correct
16 Correct 76 ms 5836 KB Output is correct
17 Correct 83 ms 6544 KB Output is correct
18 Correct 99 ms 7288 KB Output is correct
19 Correct 118 ms 7832 KB Output is correct
20 Correct 125 ms 8992 KB Output is correct