No.1687 What the Heck?
Problem Statement
Takeda and Suzuki are playing a game with the following rules.
Takeda has precognition, so he knows which card Suzuki will play in each round. The cards Suzuki plays are represented by a permutation $(P_1, P_2, \dots, P_N)$ of the integers from $1$ to $N$, and the card he plays in round $i$ is $P_i$. What is the maximum value of (the total points Takeda gets during the game)$-$(the total points Suzuki gets during the game) that can be achieved by Takeda choosing the order in which he plays his cards?
Input
$N$ $P_1$ $P_2$ $\dots$ $P_N$
Output
Print the maximum value of (the total points Takeda gets during the game)$-$(the total points Suzuki gets during the game). Print a newline at the end.
Sample
Sample 1
Input
3 3 1 2
Output
4
If Takeda plays $1$ in round $1$, $2$ in round $2$, and $3$ in round $3$, Takeda scores points in rounds $2,3$, and Suzuki scores points in round $1$. The score difference is $4$ points, and this is the maximum.
Sample 2
Input
1 1
Output
0
Takeda also has no choice but to play $1$ in round $1$. Since Takeda and Suzuki both play a card with the same integer, $1$, in round $1$, both of them get $0$ points.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
ansain
noya2