이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define N 500005
#define ll long long int
#define sz(x) (int)x.size()
#define ff first
#define ss second
ll T, n, f[N], mx[N];
pair <ll,ll> a[N];
int main(){
ios::sync_with_stdio(false); cin.tie(0);
cin >> n;
ll s = 0;
for(int i = 1; i <= n; i++){
cin >> a[i].ff >> a[i].ss;
s += a[i].ss;
}
sort(a+1,a+n+1);
for(int i = n; i >= 1; i--){
f[i] = f[i+1] + ((a[i].ff-a[i-1].ff) - a[i].ss);
mx[i] = max(mx[i+1],f[i]);
}
ll ans = max(mx[1],0LL), x = 0;
for(int i = 1; i < n; i++){
x += ((a[i+1].ff-a[i].ff) - a[i].ss);
ans = max(ans,x + mx[i+1]);
}
ans = (s - (a[n].ff - a[1].ff)) + ans;
cout << ans;
return 0;
}
# | 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... |