제출 #1342998

#제출 시각아이디문제언어결과실행 시간메모리
1342998curious_tigerArt Exhibition (JOI18_art)C++20
50 / 100
1097 ms43544 KiB
#include<bits/stdc++.h>
using namespace std;
#define ll long long

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    ll n; cin >> n;
    map<ll, ll> size_to_value;
    ll a, b;
    for (ll i=0; i<n; i++) {
        cin >> a >> b;
        size_to_value[a] += b;
    }
    vector<ll> A, B;
    for (const auto &[key, value] : size_to_value) {
        A.push_back(key);
        B.push_back(value);
    }
    n = size_to_value.size();
    vector<ll> ps_B (n+1, 0);
    for (ll i=0; i<n; i++) {
        ps_B[i+1] = ps_B[i] + B[i];
    }

    // O(n^2) algorithm
    ll ans = LLONG_MIN;
    for (ll i=0; i<n; i++) {
        ll A_min = A[i];
        for (ll j=i; j<n; j++) {
            ll A_max = A[j];
            ll S = ps_B[j+1] - ps_B[i];
            ll score = S - (A_max - A_min);
            ans = max(ans, score);
        }
    }
    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...