Пожалуйста, прочтите новое правило об ограничении использования AI-инструментов. ×

Блог пользователя lmkae

Автор lmkae, 14 месяцев назад, По-английски

[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!

Полный текст и комментарии »

  • Проголосовать: нравится
  • +10
  • Проголосовать: не нравится