Hi,
I am getting wrong answer in the follwing question:-
I am not getting which test case I am missing ,Kindly help me
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
long long int answer=0;
int n;
cin>>n;
int a[n];
int totalneg=0;
int temp;
for(int i=0;i<n;i++)
{
cin>>a[i];
}
for(int i=0;i<n;i++)
{
if(a[i]<0)
{
totalneg++;
}
}
int all;
cin>>all;
if(totalneg==0 || all==0)
{
cout<<answer<<"\n";
return 0;
}
if(totalneg<=all)
{
for(int i=0;i<n;i++)
{
if(a[i]<0)
answer=answer+fabs(a[i]);
}
}
else if(totalneg>all )
{
sort(a,a+n);
int sub=totalneg-all;
//cout<<sub;
int temp1=fabs(a[totalneg-sub]);
int p=temp1*all;
// cout<<p<<"dsadasd";
answer=answer+p;
for(int i=0;i<n;i++)
{
a[i]=a[i]+temp1;
// cout<<a[i]<<"sadsada";
}
for(int i=0;i<totalneg;i++)
{
if(a[i]<0)
{
answer=answer+fabs(a[i]);
}
}
}
cout<<answer<<"\n";
return 0;
}