1 solutions
-
0
#include<stdio.h> #include<stdlib.h> #include<math.h> int max(int a,int b){ return a < b ? b : a; } int main(){ int n; scanf("%d",&n); int arr[n + 5]; for(int i = 0; i < n; ++i){ scanf("%d",&arr[i]); } int b1 = -arr[0],s1 = 0; int b2 = -arr[0],s2 = 0; for (int i = 1; i < n; ++i){ b1 = max(b1, -arr[i]); s1 = max(s1,b1 + arr[i]); b2 = max(b2,s1 - arr[i]); s2 = max(s2,b2 + arr[i]); } printf("%d",s2); return 0; }
- 1
Information
- ID
- 9311
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 6
- Tags
- # Submissions
- 29
- Accepted
- 2
- Uploaded By