Advertisement
YEZAELP

CUBE-006: C-Value

Oct 19th, 2020
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.62 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. using lli = long long;
  5. const lli INF = 2e18;
  6.  
  7. int n;
  8. lli dp[2][3];
  9.  
  10. int main(){
  11.  
  12.     scanf("%d", &n);
  13.  
  14.     for(int i = 1; i <= n; i ++) {
  15.         lli x;
  16.         scanf("%lld", &x);
  17.         for(int cnt = 2; cnt >= 0; cnt --){
  18.             if((cnt%2 == 0 and i%2 == 1) or (cnt%2 == 1 and i%2 == 0))
  19.                 dp[i%2][cnt] = dp[(i-1)%2][cnt] - x;
  20.             else
  21.                 dp[i%2][cnt] = dp[(i-1)%2][cnt] + x;
  22.             if(cnt < 2) dp[i%2][cnt] = min(dp[i%2][cnt], dp[i%2][cnt+1]);
  23.         }
  24.     }
  25.  
  26.     printf("%lld", dp[n%2][0]);
  27.  
  28.     return 0;
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement