제출 #1179728

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

#define rep(a,b,c) for(auto a = (b); a != (c); a++)
#define repD(a,b,c) for(auto a = (b); a != (c); a--)
#define repIn(a, b) for(auto& a : (b))
#define repIn2(a, b, c) for(auto& [a, b] : (c))

constexpr bool dbg = 0;
#define DEBUG if constexpr(dbg)
#define DC DEBUG std::cerr
#define eol std::endl

#define ll long long
#define pb push_back

using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    map<ll, ll> mappy, prefSum;
    rep(i, 0, n) {
        ll x, y;
        cin >> x >> y;
        mappy[x] += y;
    }
    ll prv = 0;
    repIn2(k, v, mappy) prv += v, prefSum[k] = prv;
    prv = -5e18;
    prefSum[-1] = 0;
    auto it2 = prefSum.rbegin();
    ll ans = -5e18;
    rep(it, mappy.rbegin(), mappy.rend()) {
        it2++;
        auto k = it -> first;
        prv = max(prv, prefSum[k] - k);
        ans = max(ans, -it2 -> second + k + prv);
        DC << "maxSuf[" << k << "] = " << prv << eol;
        DC << ' ' << k << ' ' << -it2 -> second + k + prv << eol;
    }
    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...