Submission #446003

# Submission time Handle Problem Language Result Execution time Memory
446003 2021-07-20T12:07:34 Z Aryan_Raina Schools (IZhO13_school) C++17
100 / 100
130 ms 12116 KB
#include <bits/stdc++.h>
using namespace std;
 
#define int int64_t
#define ld long double
#define ar array
#define all(a) a.begin(), a.end()
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

const int INF = 1e15;
const int MOD = 1e9+7;

void solve() {
    int N, M, S; cin >> N >> M >> S;
    vector<ar<int,2>> shit(N);
    for (ar<int,2> &i : shit) cin >> i[0] >> i[1];

    sort(shit.begin(), shit.end(), [&](ar<int,2> x, ar<int,2> y) {
        return x[0] - x[1] > y[0] - y[1];
    });

    vector<int> ansA(N,0), ansB(N,0);

    priority_queue<int> pq;
    pq.push(-(ansA[0] = shit[0][0]));
    if (pq.size() > M) {
        ansA[0] += pq.top(); pq.pop();
    }
    for (int i = 1; i < N; i++) {
        ansA[i] = ansA[i-1] + shit[i][0];
        pq.push(-shit[i][0]);
        if (pq.size() > M) {
            ansA[i] += pq.top(); pq.pop();
        }
    }

    priority_queue<int>().swap(pq);
    pq.push(-(ansB[N-1] = shit[N-1][1]));
    if (pq.size() > S) {
        ansB[N-1] += pq.top(); pq.pop();
    }
    for (int i = N-2; i >= 0; i--) {
        ansB[i] = ansB[i+1] + shit[i][1];
        pq.push(-shit[i][1]);
        if (pq.size() > S) {
            ansB[i] += pq.top(); pq.pop();
        }
    }

    int ans = max(ansB[0], ansA[N-1]);
    for (int i = 0; i < N-1; i++)
        ans = max(ans, ansA[i] + ansB[i+1]);

    cout << ans << '\n';
} 
 
int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0); 
 
    int t = 1; //cin >> t;
    while (t--) solve();   
}  

Compilation message

school.cpp: In function 'void solve()':
school.cpp:26:19: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long int>::size_type' {aka 'long unsigned int'} and 'int64_t' {aka 'long int'} [-Wsign-compare]
   26 |     if (pq.size() > M) {
      |         ~~~~~~~~~~^~~
school.cpp:32:23: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long int>::size_type' {aka 'long unsigned int'} and 'int64_t' {aka 'long int'} [-Wsign-compare]
   32 |         if (pq.size() > M) {
      |             ~~~~~~~~~~^~~
school.cpp:39:19: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long int>::size_type' {aka 'long unsigned int'} and 'int64_t' {aka 'long int'} [-Wsign-compare]
   39 |     if (pq.size() > S) {
      |         ~~~~~~~~~~^~~
school.cpp:45:23: warning: comparison of integer expressions of different signedness: 'std::priority_queue<long int>::size_type' {aka 'long unsigned int'} and 'int64_t' {aka 'long int'} [-Wsign-compare]
   45 |         if (pq.size() > S) {
      |             ~~~~~~~~~~^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 0 ms 204 KB Output is correct
3 Correct 0 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 312 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 2 ms 588 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 3 ms 588 KB Output is correct
11 Correct 3 ms 460 KB Output is correct
12 Correct 2 ms 588 KB Output is correct
13 Correct 14 ms 2128 KB Output is correct
14 Correct 34 ms 3604 KB Output is correct
15 Correct 60 ms 5980 KB Output is correct
16 Correct 76 ms 8732 KB Output is correct
17 Correct 92 ms 9548 KB Output is correct
18 Correct 101 ms 10016 KB Output is correct
19 Correct 115 ms 10796 KB Output is correct
20 Correct 130 ms 12116 KB Output is correct