I am trying to solve https://www.codechef.com/LTIME57/problems/GAMENUMB - smaller case only where D[i] = 1.

What is wrong with my code.

Link : https://www.codechef.com/viewsolution/17523592

I am trying to solve https://www.codechef.com/LTIME57/problems/GAMENUMB - smaller case only where D[i] = 1.

What is wrong with my code.

Link : https://www.codechef.com/viewsolution/17523592

You are getting WA because you are directly removing the numbers while you have to remove the no. of cards of numbers. Take it like this. For

a[] = {1, 2, 3, 4, 5}

d[] = {3, 2, 5, 3, 2}

then the cards will be

1, 1, 1, 2, 2, 3, 3, 3, 3, 3, 4, 4, 4, 5, 5

let these cards be in a array c[].

then,

```
int start = 0;
int end = n;
for(int i = 0; i < k; i++) {
if((i+1) % 2 == 1 ) {
start += b[i];
}
else{
end -= b[i];
}
}
long sum = 0;
for(int i = start; i < end; i++) {
sum+=a[i];
}
```

you should use c[i] instead of the above a[i] and no. of elements of c instead of n. But It will be a very large no. So you are not advised to do so.

For better approach refer to editorial: here

Edit: The question is saying that the player is selecting b[i] cards and removing the rest while your solution removes b[i] cards. So you have to update your

if((i+1) % 2 == 1 ) { start += b[i]; } else{ end -= b[i]; }

to

if((i+1) % 2 == 1 ) { start = end - b[i]; } else{ end = start + b[i]; }

1 Like

But I am solving for smaller case only where d[i] = 1, so c[i] will be exact. copy of a[i].

Thanks for pointing out my error I have edited my answer.

1 Like

I got it myself a few minutes ago, I did read the problem properly. Anyways Thank you