Submission #1156829

#TimeUsernameProblemLanguageResultExecution timeMemory
1156829gulmixArt Exhibition (JOI18_art)C++20
0 / 100
0 ms320 KiB
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
using ll = long long;
#define all(x) x.begin(), x.end()
#define oset tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> 

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0); 
    //ifstream cin("inputf.txt");
    //ofstream cout("outputfv.txt");
    ll n; cin >> n;
    vector<pair<ll, ll>> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i].first >> a[i].second;
    }
    sort(all(a));
    ll cur = 0;
    ll ans = 0;
    ll mn = a[0].first, mx = a[0].first;
    for(int i = 0; i < n; i++){
        ll mn1 = min(a[i].first, mn); ll mx1 = max(a[i].first, mx);
        cur += a[i].second;
        if(cur - (mx1 - mn1) < 0){
            cur = 0;
            mn = a[i+1].first;
            mx = a[i+1].first;
            continue;
        }
        mn = mn1; mx = mx1;
        ans = max(ans, cur - (mx - mn));
    }
    cout << ans << '\n';
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...