投递中兴通讯等公司10个岗位 >
0 点赞 评论 收藏
分享
_春夏秋冬:和你想法一样,实现有点不同: #include <stdio.h>
#define N 100005
int main(void)
{
int t;
scanf("%d", &t);
while (t--) {
int i, n, num[N];
scanf("%d", &n);
for (i = 0; i < n; i++)
scanf("%d", num + i);
int left = 0, right = n - 1, res = 0, counted = 0;
while (right > left) {
int min = num[left] < num[right] ? num[left] : num[right];
if (min > counted) {
res += (min - counted) * (right - left);
counted = min;
}
if (num[left] < num[right])
left++;
else
right--;
}
printf("%d\n", res);
}
return 0;
}
投递深信服等公司10个岗位 >
0 点赞 评论 收藏
分享
关注他的用户也关注了: