Submission #48928

#TimeUsernameProblemLanguageResultExecution timeMemory
48928faishol27Art Exhibition (JOI18_art)C++14
0 / 100
2 ms376 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define PUB push_back struct art{ ll sz, val; }; int N; ll pref[500005]; vector<art> data; bool comp(art a, art b){ if(a.sz == b.sz) return a.val < b.val; return a.sz < b.sz; } int main(){ cin >> N; data.PUB({0,0}); for(int i=1;i<=N;i++){ ll a, b; cin >> a >> b; data.PUB({a, b}); } sort(data.begin(), data.end(), comp); for(int i=1;i<=N;i++) pref[i] = pref[i-1]+data[i].val; int l=1, r=N; ll sum_tmb = 0, sum_krg = 0; for(int i=1;i<r-1;i++){ sum_krg += data[i].val; sum_tmb += data[i+1].sz-data[i].sz; if(sum_krg < sum_tmb){ l = i+1; sum_krg = 0; sum_tmb = 0; } } sum_tmb = 0; sum_krg = 0; for(int i=r;i>l-1;i--){ sum_krg += data[i].val; sum_tmb += data[i].sz-data[i-1].sz; if(sum_krg < sum_tmb){ r = i-1; sum_krg = 0; sum_tmb = 0; } } cout << (pref[r]-pref[l-1])-(data[r].sz - data[l].sz) << endl; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...