Submission #42289

#TimeUsernameProblemLanguageResultExecution timeMemory
42289RezwanArefin01Art Exhibition (JOI18_art)C++14
100 / 100
707 ms16612 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; typedef pair<int, int> ii; const int maxn = 5e5 + 10; ll a[maxn], p[maxn]; int main(int argc, char const *argv[]) { #ifdef LOCAL_TESTING freopen("in", "r", stdin); #endif int n; cin >> n; vector<pair<ll, ll> > x(n); for(int i = 0; i < n; i++) { cin >> x[i].first >> x[i].second; } sort(x.begin(), x.end()); for(int i = 0; i < n; i++) { a[i] = x[i].first; } p[0] = x[0].second; for(int i = 1; i < n; i++) p[i] = p[i - 1] + x[i].second; // p[i] - p[j - 1] - a[i] + a[j] //=p[i] - a[i] + (a[j] - p[j - 1]) ll ans = p[0] - a[0], Max = a[0]; for(int i = 1; i < n; i++) { Max = max(Max, a[i] - p[i - 1]); ans = max(ans, p[i] - a[i] + Max); } cout << ans << 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...