제출 #258440

#제출 시각아이디문제언어결과실행 시간메모리
258440SpeedOfMagicArt Exhibition (JOI18_art)C++17
100 / 100
231 ms13176 KiB
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { ios::sync_with_stdio(0); cin.tie(); int n; cin >> n; pair<int, int> p[n]; for (int i = 0; i < n; ++i) { cin >> p[i].first >> p[i].second; } sort(p, p + n); vector<int> d(n); int s = 0; for (int i = 0; i < n; ++i) { s += p[i].second; d[i] = s - p[i].first; } for (int i = n - 2; i >= 0; --i) d[i] = max(d[i], d[i + 1]); int ans = 0; int pen = 0; for (int i = 0; i < n; ++i) { ans = max(ans, d[i] + p[i].first + pen); pen -= p[i].second; } cout << ans << endl; 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...