SHARE
TWEET

Untitled

a guest Sep 11th, 2019 90 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. #define int long long
  3. using namespace std;
  4.  
  5. signed main() {
  6.     int n;
  7.     cin >> n;
  8.     int a[n], dp[n] = {};
  9.     for (int i = 0; i < n; i++) cin >> a[i];
  10.     for (int i = 10; i < n; i++) {
  11.         int cur_min = INT_MAX;
  12.         for (int j = max(0ll, i - 9); j <= i; j++) cur_min = min(cur_min, a[j]);
  13.         for (int j = max(0ll, i - 10); j < i; j++) {
  14.             dp[i] = max(dp[j] + cur_min * (j == i - 10), dp[i]);
  15.         }
  16.     }
  17.     int sum = 0;
  18.     for (int i = 0; i < n; i++) sum += a[i];
  19.     cout << sum - dp[n - 1];
  20. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top