You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Coming up with optimal solution is ez, proving it is hard. Here goes my proof.
Case 1: If S = sum of all elements, and S/2 <= max. element. We can show that max #operations is (S-max. element).
Argue by showing that max element can pair with max S-max. element. Rest all can be paired fullest. We can't do better!!
Case 2: If S/2 > max. element we show that we can follow a process as goes below:
Choose a max element from the set, and reduce it by any(random other) element from the set till it is not maximum.
Then change max element and continue.
Let any configuration be (S,max. ele). We only change when max. (max. ele-t) >= a[x], the new configuration is (S-2t,a[x]).
Invariance is: S/2 > max. ele, in the new configuration, (S-2t)/2 = (S/2-t) > max. ele-t >= a[x], hence (S-2t,a[x]) maintains invariance.
Only thing remaining to see is that with such a invariance condition, we can always get an operation. Hence a[x] goes to 0.
Ans = S/2
A more intuitive proof for case 2. Assume that sum of the remaining element is more than the maximum element. We claim that we can always bring down the sum of the remaining element down to the maximum element and then we are done(trivial!). Only configuration which can't be reduced is [0,0,0,0,0,x], we can't bring it down to max means x>max. which is not possible
Claim: If there is a set of mice with their distances from hole sum to R and R < n. We can save all those mices.
Greedily to maximize m (#mice), we choose to reduce each distances in a sorted fashion hence selecting from end makes sense.
Proof: If R >= n then,
We can't save all mice. Why? Let say we saved m-1 mice in time q. So position of cat = q & position of mth mice= R-q.
R >=n so, R-q >= n-q. R-q+q >=n. Mice will be chased.
Consider R < n. Consider leftmost mice be positioned at l. So, R < n => R-(n-l) < l.
So when all the other cats reaches the hole, cat is still behind leftmost mice. So can be saved.
Invariance in the problem: Sum of distances of mice.
Problem 5:
In a round robin tournament, what is the maximum number of wins player ranked k can have?
Claim 1: In a greedy way let every player ranked i>k loses vs every player jk = C(N-k,2)
Claim 2: No of wins left for top j<=k teams to disribute maintaining the condition= C(K,2). Kth player should win floor(C(K,2)/K) games among them.
Idea: Whenever there is some weird process going on, think about the bipartiteness, if btw consecutive operations some structure remains intact. Then greedily solve for the varying part.