Super_Cube
2024-11-17 11:30:55
设
#include<bits/stdc++.h>
inline int calc(int x,int y){
return x+(x<y?1:x==y?0:-1);
}
int dp[300005][3];
int a[300005];
int T,n;
int main(){
dp[0][1]=dp[0][2]=0xc0c0c0c0;
scanf("%d",&T);
while(T--){
scanf("%d",&n);
for(int i=1;i<=n;scanf("%d",&a[i++]));
for(int i=1;i<=n;++i){
dp[i][0]=calc(dp[i-1][0],a[i]);
dp[i][1]=std::max(dp[i-1][0],dp[i-1][1]);
dp[i][2]=std::max(calc(dp[i-1][1],a[i]),calc(dp[i-1][2],a[i]));
}
printf("%d\n",std::max(dp[n][1],dp[n][2]));
}
return 0;
}