Saddest friend (maxim)

205 teams scored 9730 points on this task, for a maximum score of 100, an average score of 47 and a median score of 40.

Highlights

  1. Galileo Galilei, Trento is the institute with the most points (500).
  2. Lombardia is the region with the most points (1890).

Statement

Luca is giving a Christmas gift to each of his N friends! When the presents will be opened in the Giftsgiving Ceremony, his friends will be aligned in a row, numbered from 0 to N-1, and friend i will receive a gift of well-known value V_i. Luca knows that his friends will be able to see other presents at a distance up to K positions (that is, K-1 people in between). Of course, the friends whose gifts are less valuable will be sad: more precisely, their sadness will be equal to the absolute difference between the maximum value of a present they can see and the value of their one. Help Luca prepare for the ceremony by computing how sad will be the saddest friend!