Please read the new rule regarding the restriction on the use of AI tools. ×

lmkae's blog

By lmkae, 14 months ago, In English

[problem statement here]

This was a problem in my country's informatics olympiad, and I was able to reverse-engineer a solution — although I have no idea how one could make this observation in a contest. The algorithm is as follows:

  1. Input an array a and b
  2. Construct an array of the differences between a_i and b_i for each i
  3. Create a prefix sum array of the difference array
  4. Sort the prefix sum array
  5. Get the median of the prefSum array
  6. For each element p_i in the prefSum array, add the absolute difference between p_i and median to a total
  7. Output the total

Is this an already-defined type of problem, or could someone walk me through how you would arrive upon a solution? Thank you so much!

Full text and comments »

  • Vote: I like it
  • +10
  • Vote: I do not like it