Submission #672948

#TimeUsernameProblemLanguageResultExecution timeMemory
672948BaytoroSchools (IZhO13_school)C++17
100 / 100
119 ms16656 KiB
#include <bits/stdc++.h> using namespace std; #define ios ios::sync_with_stdio(false); cin.tie(NULL); #define pb push_back #define all(x) x.begin(), x.end() #define rall(x) x.rbegin(), x.rend() #define fr first #define sc second #define int long long #define endl '\n' void fopn(string name){ freopen((name+".in").c_str(),"r",stdin); freopen((name+".out").c_str(),"w",stdout); } const int INF=1e18; struct node{ int a,b,d; }; bool cmp(node a, node b){ return a.d>b.d; } int n,m,s; void solve(){ cin>>n>>m>>s; vector<node> vec(n); for(int i=0;i<n;i++){ cin>>vec[i].a>>vec[i].b; vec[i].d=vec[i].a-vec[i].b; } sort(all(vec),cmp); int sum=0; vector<int> pref(n+1),suf(n+1); priority_queue<int,vector<int>,greater<int>> dq; for(int i=0;i<n;i++){ int x=vec[i].a; dq.push(x); sum+=x; if((int)dq.size()>m){ sum-=dq.top(); dq.pop(); } pref[i]=sum; } while(!dq.empty()) dq.pop(); sum=0; for(int i=n-1;i>=0;i--){ int x=vec[i].b; dq.push(x); sum+=x; if((int)dq.size()>s){ sum-=dq.top(); dq.pop(); } suf[i]=sum; } int ans=0; for(int i=0;i<n;i++) ans=max(ans,pref[i]+suf[i+1]); cout<<ans; } main(){ //fopn("262144"); ios; int T=1; //cin>>T; while(T--){ solve(); } }

Compilation message (stderr)

school.cpp:61:1: warning: ISO C++ forbids declaration of 'main' with no type [-Wreturn-type]
   61 | main(){
      | ^~~~
school.cpp: In function 'void fopn(std::string)':
school.cpp:12:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |  freopen((name+".in").c_str(),"r",stdin);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
school.cpp:13:9: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   13 |  freopen((name+".out").c_str(),"w",stdout);
      |  ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...