BOXGAM97 Editorial

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

#include <bits/stdc++.h>
using namespace std;
int main(){
long long int t;std::cin >> t;
while(t–){
long long int n,k,p;std::cin >> n>>k>>p;
if(p==0){
long long int arr[n];long long int max=INT_MIN;long long int index;
for(long long int i=0;i<n;i++){std::cin >> arr[i];
if(max<arr[i]){
max=arr[i];
index=i;
}
}
if(k%2==1){
std::cout << max << std::endl;
}
else{
if(index==0){
std::cout << arr[index+1] << std::endl;
}
else if(index==(n-1)){
std::cout << arr[index-1] << std::endl;
}
else{
long long int a=arr[index-1];long long int b=arr[index+1];
if(a<b){
std::cout << a << std::endl;
}
else{
std::cout << b << std::endl;
}
}
}
}
else{
long long int arr[n];long long int min=INT_MAX;long long int index;
for(long long int i=0;i<n;i++){std::cin >> arr[i];
if(min>arr[i]){
min=arr[i];
index=i;
}
}
if(k%2==1){
std::cout << min << std::endl;
}
else{
if(index==0){
std::cout << arr[index+1] << std::endl;
}
else if(index==(n-1)){
std::cout << arr[index-1] << std::endl;
}
else{
long long int a=arr[index-1];long long int b=arr[index+1];
if(a>b){
std::cout << a << std::endl;
}
else{
std::cout << b << std::endl;
}
}
}

    }
}
return 0;

}

where is the problem in this
getting WA

you missed out the case ,when k is even and max/min element of array is at second position either from start or end. in that case also, the answer is max/min element of array depending on the value of p.

can someone provide a test case where my code gives WA. my code in c++ ,
#include <bits/stdc++.h>
using namespace std;
#define int long long

int32_t main()
{
ios_base ::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t, n, k, p;
cin >> t;
while (t–)
{
cin >> n >> k >> p;
vector v(n);
for (auto &i : v)
{
cin >> i;
}
auto mx = max_element(v.begin(), v.end()), mn = min_element(v.begin(), v.end());
if ((p == 0) && ((k % 2) || (mx - v.begin() == 1) || (mx - v.begin() == n - 2)))
{
cout << *mx << β€œ\n”;
}
else if ((p == 1) && ((k % 2) || (mn - v.begin() == 1) || (mn - v.begin() == n - 2)))
{
cout << *mn << β€œ\n”;
}
else
{
int m1 = 0, m2 = 0, temp1 = 0, temp2 = 0;
for (int i = 1; i < n - 1; i++)
{
temp1 = min(v[i - 1], v[i + 1]);
temp2 = max(v[i - 1], v[i + 1]);
m1 = max(m1, temp1);
m2 = min(m2, temp2);
}
if (p == 0)
{
cout << m1 << β€œ\n”;
}
else
{
cout << m2 << β€œ\n”;
}
}
}
return 0;
}