Submission #84469

#TimeUsernameProblemLanguageResultExecution timeMemory
84469hamzqq9Schools (IZhO13_school)C++14
100 / 100
378 ms22660 KiB
#include<bits/stdc++.h> #define st first #define nd second #define pb push_back #define ppb pop_back #define umax(x,y) x=max(x,y) #define umin(x,y) x=min(x,y) #define ll long long #define ii pair<int,int> #define iii pair<ii,int> #define iiii pair<ii,ii> #define sz(x) ((int) x.size()) #define orta ((bas+son)>>1) #define all(x) x.begin(),x.end() #define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" " #define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar() #define pw(x) (1<<(x)) #define inf 2005000000 #define MOD 1000000007 #define N 300005 #define M 1000005 #define LOG 18 #define KOK 4000000 using namespace std; int n,m,s; ii a[N]; ll ans; priority_queue<int> q; multiset<ii> ma,mb; int main() { //freopen("input.txt","r",stdin); scanf("%d %d %d",&n,&m,&s); for(int i=1;i<=n;i++) { scanf("%d %d",&a[i].st,&a[i].nd); } sort(a+1,a+1+n,[](ii x,ii y) { if(x.st==y.st) return x.nd<y.nd; return x.st>y.st; }); for(int i=1;i<=m;i++) { ans+=a[i].st; q.push(a[i].nd-a[i].st); } for(int i=m+1;i<=n;i++) { ma.insert(a[i]); mb.insert({a[i].nd,a[i].st}); } while(s--) { int val=q.top(); ii adda=*ma.rbegin(); ii addb=*mb.rbegin(); if(val+adda.st>addb.st) { ans+=val+adda.st; q.pop(); q.push(adda.nd-adda.st); ma.erase(prev(ma.end())); mb.erase(mb.find({adda.nd,adda.st})); } else { ans+=addb.st; mb.erase(prev(mb.end())); ma.erase(ma.find({addb.nd,addb.st})); } } printf("%lld",ans); }

Compilation message (stderr)

school.cpp: In function 'int main()':
school.cpp:36:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d %d %d",&n,&m,&s);
  ~~~~~^~~~~~~~~~~~~~~~~~~~~
school.cpp:40:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d %d",&a[i].st,&a[i].nd);
   ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...