Submission #1033980

#TimeUsernameProblemLanguageResultExecution timeMemory
1033980vjudge1Art Exhibition (JOI18_art)C++17
0 / 100
0 ms348 KiB
#include<bits/stdc++.h>
using namespace std;
const int N = 5e5;
pair<long long,long long> p[N+5];
int n;
int main(){
    cin >> n;
    for(int i = 0; i < n; i++)cin >> p[i].first >> p[i].second;
    sort(p,p+n);
    for(int i = n-1; i > 0; i--){
        if(p[i].first == p[i-1].first){
            p[i-1].second += p[i].second;
            p[i].second = 0;
        }
    }
    long long tong = p[0].second;
    long long a = p[0].first;
    long long res = tong;
    for(int i = 1; i < n; i++){
        tong+= p[i].second;
        if(tong <= p[i].first - a){
            tong = p[i+1].second;
            a = p[i+1].first;
        }
            res = max(res, tong - p[i].first + a);
    }
    cout << res;
}

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