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

    ID: 19426 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>动态规划 DP2017ICPC西安

[ICPC 2017 Xi'an R] Naomi with Array

Problem Description

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[j1]A[i], A[i+1] \dots A[j-1] one by one.
  • If i>ji > j, A[j],A[j+1]A[i1]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).

Input Format

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

In each test case:

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

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

Output Format

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