# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
840561 | overwatch9 | Art Exhibition (JOI18_art) | C++17 | 1 ms | 212 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.
// slightly modified kadane's algorithm
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using namespace std;
using ll = long long;
vector <pair <ll, ll>> pnts;
int main() {
int n;
cin >> n;
map <ll, ll> mp;
for (int i = 0; i < n; i++) {
ll a, b;
cin >> a >> b;
mp[a] += b;
}
ll ans = 0;
ll mn = mp.begin()->first;
ll mx = mn;
vector <ll> dp(mp.size());
int i = 0;
ll tot_val = 0;
for (auto it = mp.begin(); it != mp.end(); it++) {
mx = it->first;
tot_val += it->second;
ll tp_ans = tot_val - (mx - mn);
if (tp_ans <= it->second) {
mn = mx = it->first;
tot_val = it->second;
}
dp[i++] = tp_ans;
}
cout << *max_element(dp.begin(), dp.end()) << '\n';
}
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... |