代码
#include <iostream> #include <stdio.h> using namespace std; int candys[100010]; int left1[100010]; int right1[100010]; int main() { //freopen("testcase.txt", "r", stdin); int n; while(scanf("%d", &n) != EOF) { for(int i = 0; i < n; i ++) { scanf("%d", &candys[i]); } left1[0] = 1; for(int i = 1; i < n; i ++) { if(candys[i] > candys[i-1]) left1[i] = left1[i-1] +1; else left1[i] = 1; } right1[n-1] = 1; for(int i = n-2; i >= 0; i--) { if(candys[i] > candys[i+1]) right1[i] = right1[i+1] +1; else right1[i] = 1; } int maxVal = 0; for(int i = 0; i < n; i ++) { maxVal += max(left1[i], right1[i]); } printf("%d ", maxVal); } return 0; }