제출 #1266899

#제출 시각아이디문제언어결과실행 시간메모리
1266899kutomei3Art Exhibition (JOI18_art)C++20
100 / 100
343 ms12148 KiB
#include<bits/stdc++.h>
using namespace std;

#define int long long

signed main()
{
    int mx = 0, ml = 0, sa = 0;
    int n;
    cin >> n;
    int s[n], v[n];
    int ind[n];
    for (int i = 0; i < n; i++) {
        cin >> s[i] >> v[i];
        ind[i] = i;
    }
    sort(ind, ind + n, [&](int i, int j){
        return s[i] < s[j];
    });
    for (int i = 0; i < n; i++) {
        mx = max(mx, v[ind[i]]);
        mx = max(sa + v[ind[i]] + ml - s[ind[i]], mx);
        ml = max(s[ind[i]] - sa, ml);
        sa += v[ind[i]];
    }
    cout << mx;
    return 0;
}

/*
pmax - pmin - amax + amin
pmax - amax + amin - p(min - 1)
*/
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...