 # What's missing here? Question : WARRIORS;EASY

#include <stdio.h>
int main(void) {
long long int t,n,q,i,j,temp;
int count=0;
long long int p,x;
scanf("%ld",&t);
scanf("%ld %ld",&n,&q);
for(i=0;i<n;i++)
scanf("%ld",&p[i]);
for(i=0;i<q;i++)
scanf("%ld \n",&x[i]);
for (i = 0; i < n; i++) // sort in increasing order, enemy powers
{
for (j = i + 1; j < n; j++)
{
if(p[i] > p[j])
{
temp = p[i];
p[i] = p[j];
p[j] = temp;
}
}
}
for(i=0;i<q;i++)
{
for(j=0;j<n;j++)
{
if (x[i]>p[j])
{
count++;
x[i]=2*(x[i]-p[j]);
}
}
printf("%d \n",count);
count=0;
}
return 0;
}

1 Like

Bro please send a link to solution. Without syntax formatting it becomes impossible to read… It’s better if you post a link and tell your appoach as well sorry…first timer:sweat_smile:
https://www.codechef.com/viewsolution/26015579

I firstly sorted the enemy powers in ascending order, then straight away applied if else with the conditions.

https://www.codechef.com/viewsolution/26000058
Can anyone point out what is wrong with my code ?

Most certainly x[i] overflows.

How do I correct it so that mypower does not overflow ?

How do I correct the overflow?
Also, the code is working fine for a number of test cases.

Most certainly the overflow has been corrected here -https://www.codechef.com/viewsolution/26020263