Submission #473050

# Submission time Handle Problem Language Result Execution time Memory
473050 2021-09-14T21:09:20 Z robell Schools (IZhO13_school) C++17
100 / 100
133 ms 11972 KB
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef long long ll;
#define pb push_back
#define eb emplace_back
#define countbits __builtin_popcount
#define beg0 __builtin_clz
#define terminal0 __builtin_ctz
#define mod 1e9+7
void setIO(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
}
void setIO(string f){
	freopen((f+".in").c_str(),"r",stdin);
	freopen((f+".out").c_str(),"w",stdout);
	setIO();
}
int N, M, S;
pair<ll,ll> V[300000];
int main(){
	setIO();
	cin >> N >> M >> S;
    for(int i=0;i<N;i++) {
        cin >> V[i].first >> V[i].second;
    }
    sort(V,V+N);
    reverse(V,V+N);
	ll dp[N];
	priority_queue<ll> pq;
	ll cost = 0;
    for(int i=0;i<M;i++) {
        pq.push(V[i].second-V[i].first);
        cost+=V[i].first;
    }
    dp[M-1]=cost;
    for(int i = M; i < M + S; i++) {
        pq.push(V[i].second - V[i].first);
        cost += V[i].first;
        cost += pq.top(); pq.pop();
        dp[i] = cost;
    }
    ll ans = dp[M + S - 1];
    while(!pq.empty()) pq.pop();
    for(int i = M + S; i < N; i++) pq.push(V[i].second);
    cost = 0;
    for(int i = M + S - 2; i >= M - 1; i--) {
        pq.push(V[i + 1].second);
        cost += pq.top(); pq.pop();
        ans = max(ans, dp[i] + cost);
    }
    cout << ans << "\n";
}

Compilation message

school.cpp: In function 'void setIO(std::string)':
school.cpp:19:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   19 |  freopen((f+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
school.cpp:20:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   20 |  freopen((f+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
# Verdict Execution time Memory Grader output
1 Correct 0 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 204 KB Output is correct
7 Correct 2 ms 460 KB Output is correct
8 Correct 2 ms 460 KB Output is correct
9 Correct 2 ms 460 KB Output is correct
10 Correct 3 ms 460 KB Output is correct
11 Correct 3 ms 460 KB Output is correct
12 Correct 3 ms 460 KB Output is correct
13 Correct 16 ms 1912 KB Output is correct
14 Correct 31 ms 3556 KB Output is correct
15 Correct 54 ms 7948 KB Output is correct
16 Correct 70 ms 6892 KB Output is correct
17 Correct 99 ms 9160 KB Output is correct
18 Correct 104 ms 9832 KB Output is correct
19 Correct 118 ms 10728 KB Output is correct
20 Correct 133 ms 11972 KB Output is correct