Submission #211451

#TimeUsernameProblemLanguageResultExecution timeMemory
211451sevlllArt Exhibition (JOI18_art)C++14
100 / 100
239 ms40444 KiB
#include <bits/stdc++.h> using namespace std; #define int long long #define fro for #define pb push_back #define ld long double signed main() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int n; cin >> n; vector<pair<int, int>> C(n); for (int i = 0; i < n; i++) cin >> C[i].first >> C[i].second; sort(C.begin(), C.end()); vector<int> A(n); vector<int> B(n); for (int i = 0; i < n; i++) { A[i] = C[i].first; B[i] = C[i].second; } vector<int> prefb(n); prefb[0] = B[0]; for (int i = 1; i < n; i++) { prefb[i] = prefb[i - 1] + B[i]; } vector<int> C1(n), D(n); C1[0] = A[0]; D[0] = prefb[0]-A[0]; fro (int i = 1; i < n; i++) { C1[i] = A[i] - prefb[i - 1]; D[i] = prefb[i] - A[i]; } for (int i = n - 2; i >= 0; i--) { D[i] = max(D[i], D[i + 1]); } int ans = 0; for (int i = 0; i < n; i++) { ans = max(ans, C1[i] + D[i]); } 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...