mirror of
https://github.com/Kiritow/OJ-Problems-Source.git
synced 2024-03-22 13:11:29 +08:00
1b4d6396e4
2700-2799
33 lines
701 B
C++
33 lines
701 B
C++
#include<iostream>
|
|
#include<string.h>
|
|
using namespace std;
|
|
int a[150010];
|
|
int main()
|
|
{
|
|
int p,i;
|
|
while(scanf("%d",&p)!=EOF)
|
|
{
|
|
memset(a,0,sizeof(a));
|
|
for (i=1;i<=p;i++)
|
|
scanf("%d",&a[i]);
|
|
int s=0;
|
|
int x=0;
|
|
for (i=0;i<=p;i++)
|
|
{
|
|
if(x==0&&a[i]-a[i+1]<=0&&a[i+1]-a[i+2]>=0)
|
|
{
|
|
s=s+a[i+1];
|
|
x=1;
|
|
}
|
|
else
|
|
if (x==1&&a[i]-a[i+1]>=0&&a[i+1]-a[i+2]<=0)
|
|
{
|
|
s-=a[i+1];
|
|
x=0;
|
|
}
|
|
}
|
|
printf("%d\n",s);
|
|
}
|
|
return 0;
|
|
}
|