版权声明:欢迎随便转载。 https://blog.csdn.net/a1214034447/article/details/82988362
题目链接:点击这里
解题思路:
本题可以理解为前一半是每次都爬到比自己在的更高的山,后一半是每次都下到比自己更低的山.
所以答案就是2*max(a[i])
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 998244353;
const int mx = 1e3 + 10;
int n,m,a[mx],b[mx];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",a+i);
int ans = 0;
for(int i=1;i<=n;i++) ans = max(ans,a[i]);
printf("%d\n",ans*2);
return 0;
}