Im not getting correct answer please can you check
int main() {
int t;
cin>>t;
while(t--){
int n;
cin>>n;
int a[n],i;
for(i=0;i<n;i++)cin>>a[i];
// finding next greatest element to the right of an element
// and storing in array c[]
int c[n];
c[n-1]=a[n-1];
for(i=n-2;i>=0;i--){
// finding greatest element to the right starting
// from backward
c[i]=max(c[i+1],a[i+1]);
}
// if next greatest element is more that its value in
//array a[] ( original array means price on the day I purchased )
//then adding to my ans
int ans=0;
for(i=0;i<n;i++){
if(c[i]>a[i]){
//adding to my ans selling price minus purchased price
ans+=c[i]-a[i];
}
}
cout<<ans<<endl;
}
return 0;
}