BOXGAM97 Editorial

Yes reading the problem statement I also thought can means the ball can stay in same position too and got WA during contest.Instead of ‘can’ they should have used ‘must’.

I did excatly same as said in tutorial but still getting WA …
:frowning:

i also misunderstood,but problem statement is fine.but when you got to knew, you should have submitted for other case too, i didn’t even realized.

I submitted as soon as I got to know after contest :joy::joy:

i also got to know after contest:upside_down_face:

Very helpful editorial but I have a small doubt.
Why you have choose 2nd and last 2nd index for maximum and minimum neighbour in the beginning?

for very left box and very right box,because in second turn it will be moved to second right or second left ,
A[0]–>A[1]
A[n-1]–>A[n-2]

1 Like

please point out where did i go wrong?
I did exactly same thing as that of editorial

https://www.codechef.com/viewsolution/27588777

What if two boxes are containing same value and having different values of their neighboring boxes?

can someone plz explain what is happning when k is odd in the setters solution
why (ans = max(arr[2] , arr[n-1]):wink: this is needed

Hello @udayps055 ,

In the editorial it is given that when k is EVEN then jafar must choose the box such that the minimum of the neighbours is maximum possible, else if almir is starting then he should choose the box such that the maximum of his neighbours is minimum possible

So we have to look for edge cases , that is he chooses the 1st box then the only neighbour is the 2nd box
ans = arr[2]
If he chooses the last box then the its only neighbour is (n-1)th box so it will be
ans = max(ans , arr[n-1])

Instead of writing these two lines … they have written only one line as
ans = max(arr[2] , arr[n-1])

Hope you understand

Sudheera Y S
:slightly_smiling_face::smile:

2 Likes

thank u @sudheerays123

2 Likes

does it mean that on it’s first move jafar will put the ball in the box having biggest no.?

NO,not always.

then what does this sentence mean?

Jafar places the ball in the box (say x) with the maximum number written on it and in the next turn the other player will move the ball it to the left or to the right box of x then in the next turn jafar moves the ball back to the ball x and after k turns the last turn will be of jafar and in the end the ball will be in the box with maximum number written on it which is the objective of jafar so this is how he does it

Sudheera Y S
:slight_smile::smile:

2 Likes

thanks man

1 Like

Not at all :smile:

1 Like

wtf
i wrote the code for this problem and its the same idea as the editorial,
also the code are also ditto…
but then why am is getting wrong answer strange?
heres the code:
#include<bits/stdc++.h>
using namespace std;
const int MAX = 100;
int arr[MAX];
//game theory
int main(int argc, char const *argv[]) {
std::ios_base::sync_with_stdio(false);
std::cin.tie(0);
int t,n,k,p;
cin>>t;
while(t–>0)
{
int mx=INT_MIN,mn=INT_MAX,imx=1e9,inx=-1;
cin>>n>>k>>p;
for(int i=1;i<=n;i++)
{cin>>arr[i]; mx = max(mx,arr[i]); mn = min(mn,arr[i]);}
if(k%2==1)
{
if(p==0)
std::cout <<mx<< ‘\n’;
else
std::cout <<mn<< ‘\n’;
}
else
{
for(int i=2;i<=n-1;i++)
{
int a,b;
a = min(arr[i-1],arr[i+1]); b = max(arr[i-1],arr[i+1]);
imx=max(imx,a); inx = min(inx,b);
}
if(p==0)
std::cout <<imx<< ‘\n’;
else
std::cout <<inx<< ‘\n’;
}
}
return 0;
}

Plz can anyone help me in understanding the logic of this problem