Submission #1324961

#TimeUsernameProblemLanguageResultExecution timeMemory
1324961riafhasan2010Art Exhibition (JOI18_art)C++17
100 / 100
509 ms43996 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; int main() { ios::sync_with_stdio(0); cin.tie(0); int n; cin >> n; vector<pair<ll, ll>> p(1, {0, 0}); vector<ll> psum(n + 1, 0); map<ll, ll> mp; for (int i = 1; i <= n; i++) { ll a, b; cin >> a >> b; mp[a] += b; } for (auto [a, b] : mp) { p.push_back({a, b}); } n = p.size() - 1; for (int i = 1; i <= n; i++) { psum[i] = p[i].second + psum[i - 1]; } ll ans = 0; for (int i = 1, l = 1; i <= n; i++) { ll cur = psum[i] - psum[l - 1] - (p[i].first - p[l].first); ans = max(ans, cur); if (psum[i - 1] - psum[l - 1] < p[i].first - p[l].first) { l = i; ans = max(ans, psum[i] - psum[i - 1]); } } 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...