이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
typedef pair <long long, int> PLLI;
typedef long long LL;
constexpr int NMAX = 5e5 + 5;
constexpr LL INF = 1LL * 1e18;
int N;
PLLI A[NMAX];
LL sp[NMAX];
void Read () {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N;
    for (int i = 1; i <= N; ++ i )
        cin >> A[i].first >> A[i].second;
    sort(A+1, A+N+1);
}
void Solve () {
    for (int i = 1; i <= N; ++ i )
        sp[i] = sp[i-1] + 1LL * A[i].second;
    set <LL> S;
    LL ans = -INF;
    for (int i = 1; i <= N; ++ i ) {
        S.insert(sp[i-1] - A[i].first);
        LL value = *(S.begin());
        ans = max(ans, sp[i] - A[i].first - value);
    }
    cout << ans << '\n';
}
int main () {
    Read();
    Solve();
    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... |