Implemented all the logic but forgot to include the base case 1×1…
plz point out the reason why this wont get accepted…i’m a beginner…CodeChef: Practical coding for everyone
I tried (n m)/2 but that didn’t work. Then I changed it to ((nm)/2) and also added parenthesis on line 29, i.e changed ((nm)+1)/2 to (((nm)+1)/2). Anyway, thanks for pointing me towards the right direction. I was thinking that there is something wrong with my code logic.
Can Someone Please Help me where I have done mistake in Maximum Candies Problem
My code : Maximum_Candies.cpp
After reading through the comments, I feel many people missed AC(including me ) even after catching the base case but printing min(x,y). Question should have been more clear like sum must include 2 cells or something like that.
Same here
Can anyone kindly provide me with a test case where this solution does not produce correct result? Been stuck with this during the entire contest!
https://www.codechef.com/viewsolution/35981362
Got it, thanks man, your help is much appreciated.
@yash_chandnani
Can anyone plz give suggestions about my code ,i think it is considering 1x1 case also but still WA & all other suggested test cases are working too
https://www.codechef.com/viewsolution/36002649
Ok so I thought of the solution this way,
If x < y/2:
then maximum and minimum are both x
else
maximum = y and x = 0
Can anyone help me with whats wrong with this approach?
The correct answer to this test case is 95. But can you show me how this solution can be constructed?
please upload solutions of GOLOMB also.
I had the 1x1 case in my mind. But I thought that in that case the number of candies in adjacent cell should be treated as 0 and therefore the sum should be number of candies in the present cell + 0.
This one case costed me 100 points. Thank you for reviewing my code.
19 0 19
0 19 0
19 0 19
cin >> n >> m >> x >> y;
if (n == 1 && m == 1)cout << x << endl;
else if (y % 2 == 0) { //if y is even set all elements to min(x,y/2)
cout << n*m*min(x, y / 2) << endl;
} // now y is odd
else if (x <= y / 2)cout << n*m*x << endl; //set all elements to x
else { //y is odd
if ((n * m) % 2 == 1) {
cout << ((n * m) / 2 + 1)*((y + 1) / 2) + ((n * m) / 2)*(y / 2) << endl; //alternatively setting elements(y+1)/2 and y/2.
}
else cout << ((n * m) / 2)*(((y + 1) / 2) + (y / 2)) << endl;
}
I am setting all elements to (y/2) if y is even else alternatively setting elements to (y+1)/2 and y/2.
Please some one tell where I am getting wrong.
well if you check for the testcase 3 3 8 10
you will fill them like this
5 5 5
5 5 5
5 5 5
ans = 45
but the optimal solution is
8 2 8
2 8 2
8 2 8
ans = 48
Thanks a lot.
If n==m==1 just output x because it is maximum candies we can place in a cell.
now, if(x<=y)
count no. of cell whose both index sum is even i.e. (n*m+1)/2 and put x in that cell and in remaining cell put min(x,y-x);
if(x>y)
put y in cell whose both index sum is even and 0 is those both index sum is odd;
my solution Link