#include <stdio.h>
int cmp (int a,int b)
{
return ((int)a-(int)b);
}
int main()
{
int a,d,b,e,f;
scanf ("%d",&e);
while (e–)
{b=1;f=0;
scanf ("%d",&d);
while (d–)
{int c [b];
for (a=0;a <b;a++)
{
scanf ("%d",&c [a]);if (c[a]>99){
abort();
}
}
qsort (c,b,sizeof (int),cmp);
f=f+c [b-1];
b++;
}printf ("%d\n",f);
}
return 0;
}
I fixed my code AND i get the correct output.Still i get Wrong Answer by the judge.Please tell me where im wrong.
I found this somewhere down the road…
link
I think it will help.
Also, I tried checking your code but some parts went haywire. It will help if you instead posted a link to your submitted code.
Found the error:
With your code, the numbers will get sorted from smallest to largest each time they are added to the array. However, this is a bit mistaken. Your function will get the maximum sum possible within the array but NOT strictly following the rules stated at the problem. For example, you are given input of:
1
5
1
2 3
7 2 1
5 2 7 9
2 4 6 2 11
The output you will get is 31 (1 + 3 + 7 + 9 + 11) whereas the answer should be 25(1 + 3 + 1 + 9 + 11).
Hope this helps. =3