Submission #701951

#TimeUsernameProblemLanguageResultExecution timeMemory
701951NourWaelArt Exhibition (JOI18_art)C++14
0 / 100
0 ms212 KiB
#include <iostream> #include <bits/stdc++.h> typedef long long ll; using namespace std; int main() { int n; cin>>n; vector<pair<ll,ll>>art(n+1); vector<ll>prefix(n+1); for(int i=0;i<n;i++) { cin>>art[i].first; cin>>art[i].second; } sort(art.begin(),art.end()); prefix[0]=art[0].second; for(int i=1;i<n;i++) { prefix[i]+=prefix[i-1]+art[i].second; } ll fm=0; ll maxx=-1e18; ll total=0; int idx=0; for(int i=0;i<n;i++) { total+=art[i].second; if(total-art[i].first>=maxx) { maxx=total-art[i].first; fm=art[i].first; idx=i; } } int fmin=0; ll mini=-1e18; total=0; for(int i=idx;i>=0;i--) { if(i-1>=0) total=prefix[idx]-prefix[i-1]; else total=prefix[idx]; if(total-fm+art[i].first>=mini) { fmin=art[i].first; mini=total-fm+art[i].first; } } cout<<mini; return 0; }

Compilation message (stderr)

art.cpp: In function 'int main()':
art.cpp:43:10: warning: variable 'fmin' set but not used [-Wunused-but-set-variable]
   43 |      int fmin=0;
      |          ^~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...