제출 #1349896

#제출 시각아이디문제언어결과실행 시간메모리
1349896aleksandreArt Exhibition (JOI18_art)C++20
100 / 100
101 ms8764 KiB
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define ff first
#define ss second
#define pii pair<int,int>
#define endl '\n'
const int inf = 1e18;
const int N = 2e5+5;
inline void test_case() {
    int n, ans = -inf, val = -inf, pref = 0;
    cin >> n;
    vector<pii> a;
    for (int i = 0; i < n; i++) {
        int x, y; cin >> x >> y;
        a.pb({x,y});
    }    
    sort(a.begin(),a.end());
    for (int i = 0; i < n; i++) {
        val = max(val,a[i].ff-pref);
        pref += a[i].ss;
        ans = max(ans,val+pref-a[i].ff);
    }
    cout << ans << endl;
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    int T = 1;
    // cin >> T;
    while (T--) test_case();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...