제출 #1189458

#제출 시각아이디문제언어결과실행 시간메모리
1189458atillamaArt Exhibition (JOI18_art)C++20
100 / 100
109 ms15952 KiB
#pragma GCC optimize("O3")
#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;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_multiset;

#define int long long
#define double long double
#define pb push_back
#define fastio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define debug(x) cout << #x << " = " << x << '\n';
#define vdebug(a) cout << #a << " = "; for(auto x : a) cout << x << " "; cout << '\n';

const double eps = 1e-9;
const int mod = 1e9 + 7;
const int N = 2e5 + 5;
const int INF = 1e18;

signed main(){
    fastio;
    int n;
    cin >> n;
    vector<pair<int, int>> v(n + 1, {0, 0});
    for(int i = 1; i <= n; i++){
        cin >> v[i].first >> v[i].second;
    }
    sort(v.begin(), v.end());
    vector<int> pref(n + 1, 0);
    for(int i = 1; i <= n; i++){
        pref[i] = pref[i - 1] + v[i].second;
    }
    // (pref[r] - pref[l - 1] - (a[r] - a[l]))
    // (pref[r] - pref[l - 1] - a[r] + a[l])
    // ((pref[r] - a[r]) + (a[l] - pref[l]))-in max qiymetini tapmaliyig
    vector<int> x(n + 1, 0); // x[i] --> i-ci indexe qeder (a[l] - pref[l]))-in en boyuk qiymeti
    for(int i = 1; i <= n; i++){
        x[i] = max(x[i - 1], v[i].first - pref[i - 1]);
    }
    int ans = 0;
    for(int i = 1; i <= n; i++){
        ans = max(ans, (pref[i] - v[i].first) + (x[i]));
    }
    cout << ans << '\n';
}
/*
    freopen("x.in", "r", stdin);
    freopen("x.out", "w", stdout);
*/

//atilla
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...