이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
// happy
//#pragma GCC optimize("O3,unroll-loops")
//#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
#include <bits/stdc++.h>
#define int long long
//#define ll long long
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef tuple<int,int,int> tp;
const int N = 1e6 + 5;
const int oo = 1e16;
const int mod = 1e9 + 7;
const int base = 29; // >= so pt pb max
int n, a[N], b[N], sum, s[N], st[N << 2], ans;
pii p[N];
void update(int i,int x){
    i += n - 1;
    st[i] = max(st[i], x);
    while(i > 1){
        i /= 2;
        st[i] = max(st[i], x);
    }
}
int get(int l,int r){
    r++;
    int ret = -oo;
    for(l += n - 1, r += n - 1; l < r; l /= 2, r /= 2){
        if(l & 1) ret = max(ret, st[l ++]);
            if(r & 1) ret = max(ret, st[-- r]);
    }
    return ret;
}
signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    #define task "v"
    if(fopen(task ".inp","r")){
        freopen(task ".inp","r",stdin);
        freopen(task ".out","w",stdout);
    }
    cin >> n;
    for(int i = 1; i <= n; i ++){
        cin >> a[i] >> b[i];
        p[i] = {a[i], b[i]};
    }
    sort(p + 1, p + n + 1);
    update(1, 0 + p[1].fi);
    for(int i = 1; i <= n; i ++){
        s[i] = s[i - 1] + p[i].se;
        int u = get(1, i) - p[i].fi + s[i];
//        cout << p[i].fi << " " << p[i].se << " h\n";
//        cout << u << " " << i << " " << -s[i]+p[i + 1].fi << " " << get(1, i) << " " << s[i] << " " << " g\n";
        ans = max(ans, u);
        if(i + 1 <= n) update(i + 1, -s[i]+p[i + 1].fi);
    }
    cout << ans;
}
컴파일 시 표준 에러 (stderr) 메시지
art.cpp: In function 'int main()':
art.cpp:49:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |         freopen(task ".inp","r",stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
art.cpp:50:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   50 |         freopen(task ".out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~| # | 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... |