999ms

https://codeforces.com/group/XWOeQO4RLM/contest/102168/probl

Jan 26th, 2020
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.60 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. #define all(x) (x).begin(),(x).end()
  3.  
  4. using namespace std;
  5. using ll = long long;
  6.  
  7. void setmax(ll& a, ll b) {
  8.     if (a < b) a = b;
  9. }
  10.  
  11. int main() {
  12.     ios_base::sync_with_stdio(false);
  13.     cin.tie(nullptr);
  14.     cout.tie(nullptr);
  15.     int n;
  16.     cin >> n;
  17.     vector<int> a(n + 1), b(n + 1);
  18.     for (int i = 0; i < n; i++) {
  19.         cin >> a[i + 1] >> b[i + 1];
  20.     }
  21.     vector<ll> dp(n + 2);
  22.     for (int i = 0; i <= n; i++) {
  23.         setmax(dp[i + 1], dp[i]);
  24.         setmax(dp[min(i + b[i] + 1, n + 1)], dp[i] + a[i]);
  25.     }
  26.     cout << dp.back() << endl;
  27. }
Add Comment
Please, Sign In to add comment