This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |