제출 #1187541

#제출 시각아이디문제언어결과실행 시간메모리
1187541M_W_13Art Exhibition (JOI18_art)C++20
100 / 100
113 ms12108 KiB
#include <bits/stdc++.h>

using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
typedef long long ll;
#define pb push_back
#define st first
#define nd second
const ll INF = 1e18;

bool por(pair<ll, ll> a, pair<ll, ll> b) {
    return a.nd < b.nd;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    pair<ll, ll> T[n];
    rep(i, n) {
        cin >> T[i].nd >> T[i].st;
    }
    sort(T, T + n, por);
    ll maks[n + 1];
    maks[n] = -INF;
    ll S = 0;
    ll ans = 0;
    for (int i = n - 1; i >= 0; i--) {
        maks[i] = max(maks[i + 1], -S - T[i].nd);
        S += T[i].st;
        ans = max(ans, maks[i] + T[i].nd + S);
    }
    cout << ans << '\n';
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...