Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- #define all(x) (x).begin(),(x).end()
- using namespace std;
- using ll = long long;
- void setmax(ll& a, ll b) {
- if (a < b) a = b;
- }
- int main() {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- cout.tie(nullptr);
- int n;
- cin >> n;
- vector<int> a(n + 1), b(n + 1);
- for (int i = 0; i < n; i++) {
- cin >> a[i + 1] >> b[i + 1];
- }
- vector<ll> dp(n + 2);
- for (int i = 0; i <= n; i++) {
- setmax(dp[i + 1], dp[i]);
- setmax(dp[min(i + b[i] + 1, n + 1)], dp[i] + a[i]);
- }
- cout << dp.back() << endl;
- }
Add Comment
Please, Sign In to add comment