Submission #676298

#TimeUsernameProblemLanguageResultExecution timeMemory
676298vjudge1Schools (IZhO13_school)C++17
100 / 100
125 ms8992 KiB
#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 (stderr)

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 timeMemoryGrader output
Fetching results...