Submission #716595

#TimeUsernameProblemLanguageResultExecution timeMemory
716595TheSahibArt Exhibition (JOI18_art)C++17
100 / 100
761 ms42916 KiB
#include <bits/stdc++.h> #define ll long long #define oo 1e9 #define pii pair<ll, ll> using namespace std; int main() { int n; cin >> n; pii arr[n + 1]; arr[0] = {0, 0}; for (int i = 1; i <= n; i++) { cin >> arr[i].first >> arr[i].second; } sort(arr, arr + n + 1); ll pre[n + 1]; pre[0] = 0; for (int i = 1; i <= n; i++) { pre[i] = pre[i - 1] + arr[i].second; } multiset<ll> s; for (int i = 1; i <= n; i++) { s.insert(pre[i] - arr[i].first); } ll ans = 0; for (int i = 1; i <= n; i++) { auto itr = prev(s.end()); ans = max(ans, (*itr) - pre[i - 1] + arr[i].first); s.erase(s.find(pre[i] - arr[i].first)); } 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...