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>
#define int long long
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
using namespace std;
const int INFF = 1e18;
int32_t main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
vector<pair<int, int>> v(n);
for (int i = 0; i < n; i++) cin >> v[i].fi >> v[i].se;
sort(all(v));
/*
1 3
3 2
5 1
2 1 1
3 1 0
6 3 0
7 4 3
8 5 4
100 9
dp[i] = max(dp[i], dp[j] - (w[i] - w[j]) + b[i])
dp[i] = max(dp[i], dp[j] - w[i] + w[j] + b[i])
dp[i] = max(dp[i], dp[j] + w[j]) + b[i] - w[i]
*/
vector<int> dp(n, 0ll);
dp[0] = v[0].se;
int mx = dp[0] + v[0].fi;
for (int i = 1; i < n; i++) {
dp[i] = max(v[i].se, mx + v[i].se - v[i].fi);
mx = max(mx, dp[i] + v[i].fi);
}
cout << *max_element(all(dp)) << '\n';
return 0;
}
# | 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... |