Can any one help with this problem? (SALARY)


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

int main() {
// your code goes here
int t;
cin>>t;
while(t–)
{
int n;
cin>>n;
int a[n];
for(int i=0;i<n;i++)
{
cin>>a[i];
}
sort(a,a+n);
int max=a[n-1],c=0,count=0;
for(int i=0;i<n;i++)
{
if(a[i]==max)
{
count++;
continue;
}
else if(a[i]<max)
{
c+=(max-a[i]);
}
}
if(count==n)
{
cout<<“0”<<endl;
}
else
{
cout<<c<<endl;
}
}
return 0;
}
i am writing this code, can anyone help find out where it is failing?

Can you provide link to your submission?

Fails here :

1
4
1 2 2 4

Output :

5

1 Like