Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- using lli = long long;
- const lli INF = 2e18;
- int n;
- lli dp[2][3];
- int main(){
- scanf("%d", &n);
- for(int i = 1; i <= n; i ++) {
- lli x;
- scanf("%lld", &x);
- for(int cnt = 2; cnt >= 0; cnt --){
- if((cnt%2 == 0 and i%2 == 1) or (cnt%2 == 1 and i%2 == 0))
- dp[i%2][cnt] = dp[(i-1)%2][cnt] - x;
- else
- dp[i%2][cnt] = dp[(i-1)%2][cnt] + x;
- if(cnt < 2) dp[i%2][cnt] = min(dp[i%2][cnt], dp[i%2][cnt+1]);
- }
- }
- printf("%lld", dp[n%2][0]);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement