Do a Binary Search to figure out the maximum value of N such that sum of 0 - N <= S. Find out the extra portion by subtracting Sum of 0 - N from S. Check whether the remaining amount evenly divisible by K or not. Print the desired output.

Pay special attention to the Corner Cases -

  1. The Undetermined case occurs only when K = 0 and there is no extra pebbles.
  2. The NO case occurs when K = 0 and there is some extra pebbles or extra pebbles can't be divisible by K.
  3. Except for those two case, the answer is present and output the hole number.

Dataset is too strict. While doing binary search set the higher limit in such a that the desired sum of MID value does not cross the S.
Take a good care about Corner Cases.

Statistics

18% Solution Ratio
mahbubcsejuEarliest, Sep '17
nusuBotFastest, 0.0s
mahbubcsejuLightest, 131 kB
NirjhorShortest, 447B
Toph uses cookies. By continuing you agree to our Cookie Policy.