PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GD0000072. Lập lịch chuyến bay (Planning)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Lập lịch chuyến bay (Planning)

Planning

Source: Codeforces

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn flights, originally scheduled at minutes 11 through nn. Delaying flight ii by one minute costs cic_i. Due to an outage, no flight may depart during the first kk minutes. Assign each flight to a distinct minute in [k+1,k+n][k+1,k+n], never earlier than its original minute ii. Minimize total cost ∑ici(ti−i)\sum_i c_i(t_i-i) and output the new departure minute tit_i for every flight.

Input

The first line contains n,kn,k. The second line contains c1,…,cnc_1,\ldots,c_n.

Output

Print the minimum total delay cost. On the next line, print exactly nn integers tit_i in original flight order. Any feasible minimum-cost schedule is accepted.

Subtasks

  • Subtask 1 (20 points): 1≤n≤241\le n\le 24; 1≤k≤n1\le k\le n; 1≤ci≤1071\le c_i\le10^7 for every ii; departure times are distinct integers in [k+1,k+n][k+1,k+n] with ti≥it_i\ge i.
  • Subtask 2 (30 points): 1≤n≤20001\le n\le 2000; 1≤k≤n1\le k\le n; 1≤ci≤1071\le c_i\le10^7 for every ii; departure times are distinct integers in [k+1,k+n][k+1,k+n] with ti≥it_i\ge i.
  • Subtask 3 (50 points): 1≤n≤3000001\le n\le 300000; 1≤k≤n1\le k\le n; 1≤ci≤1071\le c_i\le10^7 for every ii; departure times are distinct integers in [k+1,k+n][k+1,k+n] with ti≥it_i\ge i.

Examples

Input

5 2
4 2 1 10 2

Output

20
3 6 7 4 5

Explanation

Flights originally planned at minutes 11 through 55 must use minutes 33 through 77. One optimal schedule is t=(3,6,7,4,5)t=(3,6,7,4,5) with cost 4(2)+2(4)+1(4)+10(0)+2(0)=204(2)+2(4)+1(4)+10(0)+2(0)=20. Any optimal valid schedule is accepted.