제출 #441191

#제출 시각아이디문제언어결과실행 시간메모리
441191julian33Art Exhibition (JOI18_art)C++14
0 / 100
0 ms204 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #define deb(...) logger(#__VA_ARGS__, __VA_ARGS__) template<typename ...Args> void logger(string vars, Args&&... values) { cerr<<vars<<" = "; string delim=""; (...,(cerr<<delim<<values,delim=", ")); cerr<<"\n"; } #else #define deb(...) logger(#__VA_ARGS__, __VA_ARGS__) template<typename ...Args> void logger(string vars, Args&&... values) {} #endif #define pb push_back #define sz(x) (int)(x.size()) typedef long long ll; typedef pair<int,int> pii; typedef pair<ll,ll> pll; template<typename T> inline void maxa(T& a,T b){a=max(a,b);} template<typename T> inline void mina(T& a,T b){a=min(a,b);} int main(){ cin.sync_with_stdio(0); cin.tie(0); cout.tie(0); #ifdef LOCAL freopen("input.txt","r",stdin); freopen("output.txt","w",stdout); #endif int n; cin>>n; vector<pll> art; ll sum=0; for(int i=0;i<n;i++){ ll a,b; cin>>a>>b; sum+=b; art.pb({a,b}); } sort(art.begin(),art.end()); int l=0; int r=n-1; sum-=(art[r].first-art[l].first); ll ans=sum; while(l<r){ ll el=sum-art[l].second-(art[r].first-art[l+1].first)+(art[r].first-art[l].first); ll er=sum-art[r].second-(art[r-1].first-art[l].first)+(art[r].first-art[l].first); deb(el,er); if(el>er){ sum=sum-art[l].second-(art[r].first-art[l+1].first)+(art[r].first-art[l].first); l++; } else{ sum=sum-art[r].second-(art[r-1].first-art[l].first)+(art[r].first-art[l].first); r--; } maxa(ans,sum); } cout<<ans<<"\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...