Question name finquest from algorithm section

whats wrong in this code

#include <bits/stdc++.h>
using namespace std;

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 in array c[]
	int c[n];
	c[n-1]=a[n-1];

	for(i=n-2;i>=0;i--){
		c[i]=max(c[i+1],a[i+1]);
	}

	// next greatest element is more that its value in 
	//array a[] then adding to my ans
	int ans=0;
	for(i=0;i<n;i++){
		if(c[i]>a[i]){
			ans+=c[i]-a[i];
		}
	}

	cout<<ans<<endl;
}
return 0;

}

Hello @talhashamim001 could you please explain your approach?

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.