Submission #41071

#TimeUsernameProblemLanguageResultExecution timeMemory
41071kdh9949Art Exhibition (JOI18_art)C++14
100 / 100
234 ms16396 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; using pll = pair<ll, ll>; #define X first #define Y second const int N = 500005; int n; pll a[N]; ll v[N], d[N], r; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for(int i = 1; i <= n; i++) cin >> a[i].X >> a[i].Y; sort(a + 1, a + n + 1); for(int i = 1; i <= n; i++) v[i] = a[i].Y - (a[i].X - a[i - 1].X); d[n] = v[n]; r = a[n].Y; for(int i = n - 1; i >= 1; i--){ d[i] = max(d[i + 1] + v[i], v[i]); r = max(r, d[i] + a[i].X - a[i - 1].X); } cout << r; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...