Submission #725516

#TimeUsernameProblemLanguageResultExecution timeMemory
725516vjudge1Schools (IZhO13_school)C++17
0 / 100
1 ms340 KiB
#include <bits/stdc++.h> #define F first #define S second using namespace std; using ll = long long; using PI = pair<int, int>; using PII = pair<PI, int>; int main() { freopen("school.in", "r", stdin); freopen("school.out", "w", stdout); //ios_base::sync_with_stdio(0); cin.tie(0); int n, m, s; cin >> n >> m >> s; vector<PII> vp(n+10); for(int i = 0; i < n; i++){ cin >> vp[i].F.F >> vp[i].F.S; vp[i].S = i; } vector<PII> ord; for(int i = 0; i < n; i++){ ord.push_back({{vp[i].F.F-vp[i].F.S, vp[i].F.F}, i}); } sort(ord.begin(), ord.end(), [&](PII a, PII b){ if(a.F.F != b.F.F){ return a.F.F > b.F.F; } return a.F.S > b.F.S; }); int ans = 0; int indx = 0; vector<bool> vis(n+10); while(m--){ ans += vp[ord[indx].S].F.F; vis[ord[indx].S] = true; indx++; } sort(vp.begin(), vp.end(), [&](PII a, PII b){ if(a.F.S != b.F.S){ return a.F.S > b.F.S; } return a.F.F > b.F.F; }); int cnt = 0; int i = 0; while(cnt != s && i != n-1){ if(!vis[vp[i].S]){ ans += vp[i].F.S; cnt++; } i++; } cout << ans <<"\n"; }

Compilation message (stderr)

school.cpp: In function 'int main()':
school.cpp:13:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |     freopen("school.in", "r", stdin);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
school.cpp:14:12: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   14 |     freopen("school.out", "w", stdout);
      |     ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...