Submission #197868

#TimeUsernameProblemLanguageResultExecution timeMemory
197868DS007Art Exhibition (JOI18_art)C++14
100 / 100
261 ms28792 KiB
#include <bits/stdc++.h> using namespace std; #define x first #define y second signed main() { ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n; cin >> n; pair<long long, long long> a[n]; for (int i = 0; i < n; i++) cin >> a[i].x >> a[i].y; sort(a, a + n); long long dp1[n], dp2[n]; fill(dp1, dp1 + n, 0); fill(dp2, dp2 + n, 0); dp1[0] = a[0].x + a[0].y; for (int i = 1; i < n; i++) dp1[i] = max(dp1[i - 1] + a[i].y, a[i].x + a[i].y); dp2[n - 1] = a[n - 1].y - a[n - 1].x; for (int i = n - 2; i >= 0; i--) dp2[i] = max(dp2[i + 1] + a[i].y, a[i].y - a[i].x); long long ans = 0; for (int i = 0; i < n; i++) ans = max(ans, a[i].y); for (int i = 0; i < n - 1; i++) ans = max(ans, dp1[i] + dp2[i + 1]); cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...