이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <algorithm>
#include <vector>
#define fs first
#define sc second
using namespace std;
using ll = long long int;
const int N = 5e5 + 5;
pair<ll, ll> a[N];
ll ans = 0, mx = 0, pref[N];
bool cmp(pair<ll, ll> a, pair<ll, ll> b) {
return a.fs < b.fs;
}
int main() {
int n; cin >> n;
for (int i = 1; i <= n; ++i)
cin >> a[i].fs >> a[i].sc;
sort(a+1, a+n+1, cmp);
for (int i = 1; i <= n; ++i)
pref[i] = pref[i - 1] + a[i].sc;
for (int i = 1; i < n; ++i) {
mx = max(mx, a[i].fs - pref[i-1]);
ans = max(ans, pref[i] - a[i].fs + mx);
}
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... |