📄 2982611_ac_1888ms_5272k.java
字号:
import java.util.*;
public class Main {
public static void main(String[] args) {
Scanner cin = new Scanner (System.in);
int i, j, ans, n, k;
boolean c;
int m;
int t[] = new int [150001];
ans = 0;
n = cin.nextInt();
for(i = 1; i <= n; i++)
{
t[i] = cin.nextInt();
}
k = 1;i = 1;
c = true;m = 0;
while(i <= n)
{
if(k%2!=0)
{
c = true;
for(j = i; j < n; j++)
{
if(t[j]>t[j+1])
break;
}
ans += t[j];
i = j+1;
}
else
{
c = false;
for(j = i; j < n; j++)
{
if(t[j]<t[j+1])
break;
}
ans -= t[j];
m = t[j];
i = j+1;
}
k++;
}
if(!c)
ans += m;
System.out.println(ans);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -