PROBLEM LINK:Author: Sunny Aggarwal DIFFICULTY:Cakewalk PREREQUISITES:Adhoc PROBLEM:Given are the number of apples ($N$) and oranges($M$) and $k$, i.e., the amount of money that chef has to buy apples/oranges. Each orange/apple costs 1 unit. What is the minimum difference that can be achieved. EXPLANATION:The problem is a very direct one. We have to minimize the difference. We can only increase the number of apples or oranges that we have. The logical step is to increase that commodity which is less because increasing the which is already more will only increase the the difference. Let $minC$ denote the quantity which is less. Let $maxC$ be the quantity which is more. The answer is given by: $ans = maxC  min(minC+k, maxC)$ We have a min operation in the second term because the optimal case is to make both the quantities equal. If we have enough money to increase the lesser one to more than the other one, then we would rather make them equal so as to have a difference of zero, which is optimal. COMPLEXITY:$\mathcal{O}(1)$ per test case. SAMPLE SOLUTIONS:
This question is marked "community wiki".
asked 21 Jan '16, 18:56

include <stdio.h>int same(int ,int ,int); int fgreat(int ,int ,int); int main(void) {
}
int same(int n,int m,int k)
{
if(k%2==0)
{
n+=k/2;
m+=k/2;
}
else
{
n+=k/2;
m+=kk/2;
} what is wrong in this code? answered 05 Feb '16, 03:09

All 3 solution links are broken. Great. :( Don't know why such a well known issue crops up each time. answered 29 Feb '16, 02:11
Check this out: https://www.codechef.com/viewsolution/9223853
(29 Feb '16, 05:07)

https://www.codechef.com/viewsolution/10575699 What is wrong with my solution? Can anybody please help me cuz its supposed to be working fine for all test cases. answered 22 Jun '16, 17:42

include<iostream>using namespace std; int main() { int t; cin>>t; while(t) { int n,m,k; cin>>n>>m>>k; while(k) { if(n<m) n="n+1;" else="" if(m="=n)" n="n+1;" else="" m="m+1;" }="" if(n="">m) cout<<nm<<"\n"; else="" cout<<mn<<"\n";="" }="" return(0);="" }<="" p="">
link
This answer is marked "community wiki".
answered 27 Jun '16, 18:56

T=input() C=0 while C<T :
answered 13 Sep '16, 18:23

In your while loop you are checking if(t1>t2) or not. answered 23 Apr '17, 09:35

Can anyone explain me the condition 3 4 4 ? According to the formula the answer is coming as 0. But the answer should come as 1. Can anyone explain me this? answered 19 Sep '17, 20:38

Calculate the absolute difference between no. of apples and oranges. We can further minimize this difference by buying either of apple or oranges accordingly:
Spend all our coins to buy fruits accordingly. Minimum absolute difference can be 0 only, so for negative answer output 0 i.e. dont spend more coins afterwards we've equal no. of fruits:
answered 12 Oct '17, 12:13

include<stdio.h>include<stdlib.h>int main() { int t,n,m,k; scanf("%d",&t); while(t) { scanf("%d %d %d",&n,&m,&k); while(k) {
} printf("%d\n",abs(mn)); } return 0; } This is my code. It resulted WA. Can you help me to find error ? condition in if : n is less than or equal to. answered 16 Mar, 17:45
