[요약] L (4 <= L <= 32,768) 길이의 팔찌에 C (1 <= C <= 512) 개의 부적들이 팔찌의 왼쪽 기준으로 P_i (0 <= P_i <= L) 번째에 위치하고, S_i (1 <= S_i <= 25)의 길이만큼 매달려있다. N의 위치에 못을 박게 되면, 모든 팔찌들과 매달린 부적들은 중력의 영향으로 아래로 처지게 되는데, 이 때의 못과 부적 사이의 길이를 구하여라.
Margaret snatches the bracelet from Bessie and nails it (with a zero-width nail) to a fencepost. The nail is located N mm (1 <= N <= L-1) from the left side of the bracelet, and the bracelet itself thus hangs left and right of the nail, with gravity pulling the bracelet and charms straight down.
Bessie is curious: How far is each charm from the nail in the fencepost?
By way of example, consider a bracelet of length 16 mm with three charms. The schematic diagram below shows + signs which are each separated by 1 mm and vertical bars which each represent 1mm of an attached string. The charms are defined to be 4, 7, and 3 mm from the bracelet.
1 1 1 1 1 1 1 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | | | | | | | * * | | | *When the bracelet is nailed to the fencepost with the nail at location 5, it droops like this (please ignore the left-right spread which is shown for clarity):
Droop Bracelet Bracelet dist. location location 0 5 + 5 <---- nail is here 1 4 + + 6 2 3 | + + 7 3 2 | + + 8 D 4 1 | + + 9 O 5 0 * + + | 10 W 6 + | 11 N 7 + | 12 | 8 + | 13 | 9 + | 14 V 10 + | 15 11 + * 16 12 | 13 | 14 *
As you can see, the first charm droops down 5 mm from the nail; the second charm droops to 11 mm and the third charm all the way down to 14 mm from the nail.
Calculate the charm droop distance for each charm given.
입력 16 3 5 4 4 7 9 3 16 출력 5 11 14
출처:usaco 2011 MAR bronze 요약: pl0892029