시간 제한메모리 제한제출정답맞힌 사람정답 비율
1 초 1024 MB61292950.000%

문제

The Info(1)cup Kingdom hosts the largest cook-off in history. Two of the kingdom’s largest chefs, Lulu and Tanaka both want to prove that they are the best chef in the kingdom. However, the cooking contest is a bit strange: it involves breaking plates. Each contestant receives $n$ plates of distinct sizes, where each has a certain value. Formally, you receive $n$ plates, ordered from largest to smallest, and their values $v_1, \dots , v_n$. Now, each contestant stacks the plates in any order they want. When a plate is added to the stack, all plates that are smaller than it are broken and removed from the stack. The score of the current plate is calculated as number_of_plates_broken × $v_i$, if the value of the plate is $v_i$. The total score of a contestant’s performance is the sum of the scores for each of the plates. After hearing about this task, Tanaka says to Lulu: “Beating you will be ez, Lulu”. Help Lulu beat Tanaka by finding the best possible order in which to put the plates on the stack.

입력

The first line of the input contains $n$, the number of plates. The next line contains $v_1, \dots , v_n$.

출력

The first line of the output contains a single integer which is the maximum score Lulu can make.

The second contains the order in which Lulu should insert the plates in order to achieve this score. For example, if the order is “add the third plate, then the first, then the second”, the output should contain 3 1 2. If there are multiple orders you can print any one of them.

제한

  • $1 ≤ n ≤ 200\,000$.
  • $1 ≤ v_i ≤ 1\,000\,000\,000$.
  • If only the maximum score is correct, then only 50% of the points for the test are awarded.

서브태스크

번호배점제한
112

$v_i = i$

213

$v_i = n + 1 - i$

322

$1 ≤ n ≤ 9$

453

No further restrictions.

예제 입력 1

3
1 2 3

예제 출력 1

3
3 2 1

Firstly, we put the third plate on the stack. The second plate breaks the third one, with a score of $1 · 2 = 2$. The first one then breaks the second one, with a score of $1 · 1 = 1$.

예제 입력 2

3
3 2 1

예제 출력 2

6
2 3 1

Firstly, we put the second plate on the stack. Then we put the third plate which doesn't break anything. Then the first one will break the first two with a score of $2 · 3 = 6$.

예제 입력 3

10
2 2 1 24 13 15 20 10 29 29

예제 출력 3

155
3 5 6 7 8 10 9 4 2 1

The explanation for this example is truly remarkable, but this margin is too small to contain it

채점 및 기타 정보

  • 예제는 채점하지 않는다.