제출 #1337422

#제출 시각아이디문제언어결과실행 시간메모리
1337422nagorn_phArt Exhibition (JOI18_art)C++20
0 / 100
1 ms348 KiB
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

#define ordered_set <int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define ordered_multiset <int, null_type, less_equal <int>, rb_tree_tag, tree_order_statistics_node_update>

#define int long long
#define double long double
#define pii pair <int, int>
#define tiii tuple <int, int, int>
#define tiiii tuple <int, int, int, int>
#define emb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define iShowSpeed cin.tie(NULL)->sync_with_stdio(false)
#define matrix vector <vector <int>>
#define mat(n, m) vector <vector <int>> (n, vector <int> (m));

const int mod = 1e9 + 7;
const int inf = 1e18;
const matrix II = {{1, 0}, {0, 1}};

void solve(){
    int n; cin >> n;
    vector <pii> a(n + 1); for (int i = 1; i <= n; i++) cin >> a[i].first >> a[i].second;
    sort(all(a));
    vector <int> pref(n + 1); for (int i = 1; i <= n; i++) pref[i] = pref[i - 1] + a[i].second;
    int mx = pref[n] - a[n].first;
    int ans = a[n].second;
    for (int i = n - 1; i >= 1; i--) ans = max(ans, a[i].first - pref[i - 1] + mx), mx = max(mx, pref[i] - a[i].first);
    cout << ans;
}

int32_t main(){
    iShowSpeed;
    // int q; cin >> q; while (q--) 
    solve();
}

/*
for an index i -> ans = max(pref[j] - pref[i - 1] - (a[j] - a[i]))
                      = a[i] - pref[i - 1] + max(pref[j] - a[j]);
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...