Hello everyone,
I have been trying to solve a question ZUMA in spoj w/o DP.
But the judge is giving me a wrong answer, although I have tested for some of the test cases myself.
The following is the code which I have written:
# include < bits/stdc++.h >
using namespace std;
int main()
{
int i,n,k,c=0,l=0;
scanf("%d %d", &n, &k);
int a[n];
for(i=0;i < n;i++)
scanf("%d", &a[i]);
sort(a,a+n);
for(i=0;i < n-1;)
{
c=1;
while(a[i]==a[i+1])
{
if(c < k)
c++;
i++;
}
l+=k-c;
i++;
}
if(a[n-1]!=a[n-2])
l+=k-1;
printf("%d\n", l);
return 0;
}