Previously, the sum of the largest continuous subsequences was developed by myself. linear algorithms are quite simple. I haven't updated my problem solution for a long time. I don't know when I will be able to come out of the solution for 1,000, so I have a good question. In a sequence, take the numbers. The odd digits are the plus digits, and the even digits are the minus digits. The greatest sum is required. I had no idea, and I was not planning to think about it. I was too tired at noon. I had A rest and thought about it after I got up. I wrote 1A and wrote A again. Well, this is A question of water. I only want to cheat =
#include<iostream>#define MAXN 150001using namespace std;int date[MAXN];int main(){ int n,i; while( scanf( "%d",&n )!=EOF ) { date[0]=0; for( i=1;i<=n;i++ ) scanf( "%d",&date[i] ); int ans=0; i=0; while( date[i+1]>=date[i] ) i++; ans+=date[i]; for(;i<=n;i++ ) { while( date[i+1]<=date[i] && i<=n ) i++; if( i!=n ) ans-=date[i]; while( date[i+1]>=date[i] && i<=n ) i++; ans+=date[i]; } printf( "%d\n",ans ); } return 0;}
#include<iostream>#define MAXN 150001using namespace std;int max( int a,int b ){ return a>b?a:b; }int main(){ int n,i; while( scanf( "%d",&n )!=EOF ) { bool add=true; int a,b; a=0;int ans=0; scanf( "%d",&a ); for( i=2;i<=n;i++ ) { scanf( "%d",&b ); if( add ) { if( a>b ) { add=!add; ans+=a; } if( b>=a && i==n ) ans+=b; } else { if( a<b ) { add=!add; ans-=a; } if( a<b && i==n ) ans+=b; } a=b; } printf( "%d\n",ans ); } return 0;}
But it's still not fast to write it out... it's fast !!