sir, can you give and explain the solution for problem b…luba and the ticket…of educational codeforces round 27.
link:https://codeforces.com/contest/845/problem/B
Educational codeforces round 27...problem b
Hey , Assume that the sum of the first three digits is less than the sum of the last 3. Let the difference between the halves be d. You want to increase the sum of the first half and/or decrease the sum of the second half so that d = 0. If you have a digit, x, in the first half, you can use that the decrease d by (9 — x). Similarly, if you have a digit, y, in the second half, you can use that digit to decrease d by y. So, just put all (9-x)s and ys into a list, sort, and greedily subtract the largest values until d <= 0.
In question it was given by example,
123456, divide it in half.
123 | 456
sum of first 3 digit = 6
Sum of last 2 digit = 15
Difference between them is = 9
Find elements having sum 9 or any element which is equal to 9. Here they are 4&5 so make them 0 and result is 2.
Code ;
https://topic.alibabacloud.com/a/codeforces-845b-luba-and-the-ticket-greedy_8_8_10262106.html
Rest,You can do it on your own.