好久没有做edu的b做到流汗了,很吊的一个思维(递推)题

给定一个now代表来到位置i,左边可用的芯片数,如果now>ai那么说明不会产生新的贡献,只需要更新一下now即可,否则我需要加上一个差值并更新now
cpp
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define endl '\n'
using namespace std;
typedef pair<int,int> pii;
const int N=1e6+10;
const int mod=998244353;
vector<int>pm;
int judge[N],nm[N],inv[N];
int Log2[N];
int kmi(int a,int b){
int res=1;
while(b){
if(b&1) res=res*a%mod;
a=a*a%mod;
b>>=1;
}
return res;
}
void init(){
nm[0]=inv[0]=1;
for(int i=1;i<=1e6;i++){
nm[i]=nm[i-1]*i%mod;
inv[i]=kmi(nm[i],mod-2);
}
}
void euler(int n){
judge[1]=1;
for(int i=2;i<=n;i++){
if(!judge[i]){
pm.push_back(i);
}
for(int j=0;pm[j]*i<=n;j++){
judge[pm[j]*i]=1;
if(i%pm[j]==0) break;
}
}
}
int C(int a,int b){
return nm[a]*inv[a-b]%mod*inv[b]%mod;
}
void solve(){
int n;cin>>n;
int now=1;
int ans=0;
for(int i=1;i<=n;i++){
int x;cin>>x;
if(x<=now){
now=x;
}
else{
ans+=x-now;
now=x;
}
}
cout<<ans<<endl;
}
signed main(){
ios::sync_with_stdio(0);cin.tie(0);
// for(int i=2;i<=1e6;i++){
// Log2[i]=Log2[i/2]+1;
// }
int T=1;cin>>T;
while(T--) solve();
return 0;
}