# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
259833 | shivensinha4 | Art Exhibition (JOI18_art) | C++17 | 4 ms | 1152 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;
#define for_(i, s, e) for (int i = s; i < e; i++)
#define for__(i, s, e) for (ll i = s; i < e; i++)
#define SSTR(x) static_cast<std::ostringstream&>((std::ostringstream() << std::dec << x)).str()
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> ii;
#define endl '\n'
int main() {
#ifndef ONLINE_JUDGE
freopen("test.in", "r", stdin);
#endif
ios_base::sync_with_stdio(false);
cin.tie(0);
int n; cin >> n;
vector<pair<ll, ll>> nums(n); // size, val
for_(i, 0, n) cin >> nums[i].first >> nums[i].second;
sort(nums.begin(), nums.end());
vector<ll> dp(n);
dp[n-1] = nums[n-1].second - nums[n-1].first;
for (int i = n-2; i >= 0; i--) {
dp[i] = max(nums[i].second - nums[i].first, nums[i].second + dp[i+1]);
}
ll ans = 0;
for_(i, 0, n) ans = max(ans, dp[i]+nums[i].first);
cout << ans << endl;
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... |