### arpit92_8's blog

By arpit92_8, history, 9 days ago,

This is the problem of cses coin piles I have only one doubt why we have to check for this condition min(a, b) * 2 >= max(a, b)? and other approaches and hints will be highly appreciated.

• +4

 » 9 days ago, # | ← Rev. 2 →   0 No we dont need that condition My wayint query() { int a, b; cin >> a >> b; while (true) { /// Assume a < b and make them balance if (a > b) swap(a, b); int A = min(a / 1, b - a); /// Remove first 1 in a then 2 in b: min(a / 1, b - a) int B = min(b / 2, b - a); /// Remove first 2 in b then 1 in a: min(b / 2, b - a) int t = max(A, B); /// Select better way if (t == 0) break; /// Both remain the same a -= t; b -= t * 2; } /// Remove (1 in a, 2 in b) and (2 in a, 1 in b) at the same time int t = min(a, b) / 3; a -= t * 3; b -= t * 3; cout << (a == 0 && b == 0 ? "YES\n" : "NO\n"); return 0; } 
•  » » 8 days ago, # ^ |   0 thank you but i am not able to understand your code
•  » » » 8 days ago, # ^ |   0 At which part ? :(
 » 9 days ago, # |   +3 You can construct the equation system and find out. The solution must be nonnegative integers.Let x be the number of moves that remove one coin from the left pile and two coins from the right pile. Let y be the number of moves that remove two coins from the left pile and one coin from the right pile. This yields a system of equations that you can solve: a = x + 2y, b = 2x + y. Through solving the system, you can rederive the condition you mentioned.
•  » » 8 days ago, # ^ | ← Rev. 3 →   0 thank you for the reply i understand your concept up to some extent om solving the eqns i am getting two condition conditions2*a>=b2*b>=abut from where max and min is coming into picture?
 » 9 days ago, # |   0 take both piles mod 3 then hardcode in 2-1 2-0 etc
•  » » 8 days ago, # ^ |   0 thank you for the reply but i couldnt understnd the line ** hardcode in 2-1 2-0 etc**?