# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
895327 | Isam | Art Exhibition (JOI18_art) | C++17 | 0 ms | 348 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include<bits/stdc++.h>
using namespace std;
constexpr int sz = 1e6 + 5;
signed main(){
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int N;
cin >> N;
vector<pair<int, int>> A(N+1);
vector<long long> pref(N), cost(N);
for(register int i(0); i < N; ++i){
cin >> A[i].first >> A[i].second;
}
sort(A.begin(), A.end());
for(register int i(0); i < N; ++i){
pref[i] = (i ? pref[i-1] : 0ll) + A[i].second;
}
for(register int i(N - 1); i >= 0; --i){
cost[i] = max((i < N - 1 ? cost[i+1] : -100000000), pref[i] - A[i].first);
}
long long ans{-1000000000};
for(register int i(0); i < N; ++i){
ans = max(ans, cost[i] - ((i ? pref[i-1] : 0ll) - A[i].first));
}
cout << ans << '\n';
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |