이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pll pair<ll,ll>
#define fi first
#define se second
ll N;
pll arr[500100];
ll psum[500100];
ll ans=-1e18, maks=-1e18;
int main()
{
cin >> N;
for(int i=1; i<=N; i++) {
cin >> arr[i].fi >> arr[i].se;
}
sort(arr+1, arr+N+1);
for(int i=1; i<=N; i++) {
psum[i] = psum[i-1] + arr[i].se;
}
for(int i=N; i>=1; i--) {
maks = max(maks, psum[i]-arr[i].fi);
ans = max(ans, maks + arr[i].fi-psum[i-1]);
}
cout << ans << endl;
}
| # | 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... |