# | Submission time | Handle | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
200329 | 2020-02-06T10:49:34 Z | blue | Art Exhibition (JOI18_art) | C++17 | 0 ms | 0 KB |
#include <iostream> using namespace std; long long* X; long long* Y; bool f(long long a, long long b) { return X[a] < X[b]; } int main() { long long N; cin >> N; X = new long long[N+1]; Y = new long long[N+1]; long long A[N+1], B[N+1]; for(long long i = 1; i <= N; i++) cin >> X[i] >> Y[i]; long long I[N+1]; for(long long i = 0; i <= N; i++) I[i] = i; sort(I+1, I+N+1, f); long long a = 1; for(long long i:I) { if(i == 0) continue; A[a] = X[i]; B[a] = Y[i]; a++; } for(long long i = 2; i <= N; i++) B[i] += B[i-1]; A[0] = B[0] = 0; for(long long i = 1; i <= N; i++) { X[i] = A[i] - B[i-1]; Y[i] = B[i] - A[i]; } for(long long i = N-1; i >= 1; i--) Y[i] = max(Y[i], Y[i+1]); long long res = 0; for(long long i = 1; i <= N; i++) res = max(res, X[i] + Y[i]); cout << res << '\n'; return 0; }