#P17148. [ICPC 2017 Xi'an R] Naomi with Array

    ID: 16754 Type: RemoteJudge 1000ms 512MiB Tried: 0 Accepted: 0 Difficulty: 9 Uploaded By: Tags>动态规划 DP2017ICPC西安

[ICPC 2017 Xi'an R] Naomi with Array

题目描述

Now Naomi is facing another math problem.

Naomi has an 11-indexed array which contains nn different non-negative numbers. She needs to move the numbers to make the array in descending order. Each move Naomi can choose ii, jj and move the number of position ii to position jj with cost i+ji+j.

Suppose she moves the number of position ii to position jj:

  • If i<ji < j, A[i+1],A[i+2]…A[j]A[i+1], A[i+2] \dots A[j] move to A[i],A[i+1]…A[j−1]A[i], A[i+1] \dots A[j-1] one by one.
  • If i>ji > j, A[j],A[j+1]…A[i−1]A[j], A[j+1] \dots A[i-1] move to A[j+1],A[j+2]…A[i]A[j+1], A[j+2] \dots A[i] one by one.

Naomi wants to minimize the sum of costs from each move. But it’s not enough, Naomi wants to know how many moves at least (also the sum of costs should be minimal).

输入格式

The input contains multiple test cases. (No more than 2020)

In each test case:

The first line contains one number nn (1≤n≤10001 \le n \le 1000).

The following line contains nn numbers denoting array AA. Each number in array AA will be less than 10810^8.

输出格式

For each test case, print the minimum sum of the costs and the minimum moves in a single line. Separate them by one space.

5
10 13 4 8 7
11 2