제출 #1181650

#제출 시각아이디문제언어결과실행 시간메모리
1181650Born_To_LaughArt Exhibition (JOI18_art)C++17
100 / 100
130 ms12112 KiB
// Born_To_Laugh - Hughie Do
#include <bits/stdc++.h>
#define alle(sth) sth.begin(), sth.end()
using namespace std;
typedef long long ll;
[[maybe_unused]] const ll MOD = 998244353, INF = 1e18 + 7;
#define int ll
void solve(){
    int n;cin >> n;
    vector<pair<int,int>> a(n);
    for(int i=0; i<n; ++i){
        cin >> a[i].first >> a[i].second;
    }
    sort(alle(a));
    vector<int> pref(n);
    pref[0] = a[0].second;
    for(int i=1; i<n; ++i){
        pref[i] = pref[i-1] + a[i].second;
    }
    int ans = 0;
    for(int i=0; i<n; ++i)ans = max(ans, a[i].second);
    int x = -INF;
    for(int j=1; j<n; ++j){
        int num = a[j-1].second + a[j-1].first - pref[j-1];
        x = max(x, num);

        int res = a[j].second - a[j].first + pref[j-1];
        res += x;
        ans = max(ans, res);
    }
    cout << ans << '\n';
}
signed main(){
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    solve();
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...