Submission #331888

#TimeUsernameProblemLanguageResultExecution timeMemory
331888uroskArt Exhibition (JOI18_art)C++14
0 / 100
1 ms364 KiB
//sat #include <chrono> using namespace std::chrono; #define vremestart auto start = high_resolution_clock::now(); #define vremeend auto stop = high_resolution_clock::now(); #define vremeispis auto duration = duration_cast<microseconds>(stop - start); cout << duration.count() << endl; //sat #include <bits/stdc++.h> #define mod 998244353 #define gcd __gcd #define ll long long #define ull unsigned long long #define llinf 9223372036854775807 #define iinf 2147483647 #define pb push_back #define popb pop_back #define fi first #define sc second #define pii pair<int,int> #define pll pair<ll,ll> #define sz(a) int(a.size()) #define all(a) a.begin(),a.end() #define rall(a) a.begin(),a.end(),greater<int>() using namespace std; #define maxn 500005 pll a[maxn]; int n; bool cmp(pll x,pll y){ return x.fi<y.fi; } int main(){ ios_base::sync_with_stdio(false);cerr.tie(0);cout.tie(0);cin.tie(0); cin >> n; ll ans = 0; for(int i = 1;i<=n;i++){ cin >> a[i].fi >> a[i].sc; ans+=a[i].sc; } sort(a+1,a+n+1,cmp); int i = 1; int j = n; ans+=a[1].fi-a[n].fi; // cerr<<ans<<"\n"; while(i<j){ if(ans-a[i].sc-a[i].fi+a[i+1].fi>ans-a[j].sc+a[j].fi-a[j-1].fi){ ans = max(ans,ans-a[i].sc-a[i].fi+a[i+1].fi); i++; }else{ ans = max(ans-a[j].sc+a[j].fi-a[j-1].fi,ans); j--; } } cout<<ans; return 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...