Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are n flights that must depart today, the i-th of them is planned to depart at the i-th minute of the day.

Metropolis airport is the main transport hub of Metropolia, so it is difficult to keep the schedule intact. This is exactly the case today: because of technical issues, no flights were able to depart during the first k minutes of the day, so now the new departure schedule must be created.

All n scheduled flights must now depart at different minutes between (k + 1)-th and (k + n)-th, inclusive. However, it's not mandatory for the flights to depart in the same order they were initially scheduled to do so — their order in the new schedule can be different. There is only one restriction: no flight is allowed to depart earlier than it was supposed to depart in the initial schedule.

Helen knows that each minute of delay of the i-th flight costs airport ci burles. Help her find the order for flights to depart in the new schedule that minimizes the total cost for the airport.

Input

The first line contains two integers n and k (1 ≤ k ≤ n ≤ 300 000), here n is the number of flights, and k is the number of minutes in the beginning of the day that the flights did not depart.

The second line contains n integers c1, c2, ..., cn (1 ≤ ci ≤ 107), here ci is the cost of delaying the i-th flight for one minute.

Output

The first line must contain the minimum possible total cost of delaying the flights.

The second line must contain n different integers t1, t2, ..., tn (k + 1 ≤ ti ≤ k + n), here ti is the minute when the i-th flight must depart. If there are several optimal schedules, print any of them.

Example
input
5 2
4 2 1 10 2
output
20
3 6 7 4 5
Note

Let us consider sample test. If Helen just moves all flights 2 minutes later preserving the order, the total cost of delaying the flights would be(3 - 1)·4 + (4 - 2)·2 + (5 - 3)·1 + (6 - 4)·10 + (7 - 5)·2 = 38 burles.

However, the better schedule is shown in the sample answer, its cost is (3 - 1)·4 + (6 - 2)·2 + (7 - 3)·1 + (4 - 4)·10 + (5 - 5)·2 = 20burles.

题意:

飞机出发时间是1->n 现在一开始就晚点m小时,那么给出推迟1小时有损失的费用,问如何规定使得损失最小

解法:

1 自然出发时间不能早于原始的出发时间

2 1->n的出发时间自动推到1+m->n+m,我们想到只要距离原始出发时间最近就行

3 费用最高的优先讨论

 #include<bits/stdc++.h>
using namespace std;
long long n,k;
struct Node{
long long num;
int pos;
}node[];
bool Sort(Node x,Node y){
if(x.num==y.num){
return x.pos<y.pos;
}
return x.num>y.num;
}
long long sum;
set<int>Se;
int X[];
int main(){
scanf("%d%d",&n,&k);
for(int i=;i<=n;i++){
scanf("%d",&node[i].num);
node[i].pos=i;
Se.insert(i+k);
}
sort(node+,node++n,Sort);
for(int i=;i<=n;i++){
// cout<<node[i].num<<"A "<<node[i].pos<<endl;
int ans=*Se.lower_bound(node[i].pos);
sum+=(ans-node[i].pos)*node[i].num;
X[node[i].pos]=ans;
Se.erase(ans);
}
cout<<sum<<endl;
for(int i=;i<=n;i++){
cout<<X[i]<<" ";
}
return ;
}

最新文章

  1. WPF 开源Chart控件
  2. js调试--查找dom对象绑定的函数
  3. 自我反思--table的简单数据分页
  4. 关联分析---Apriori
  5. 《SQL Server企业级平台管理实践》读书笔记——SQL Server中收缩数据库不好用的原因
  6. SqlHelper类的使用
  7. Java安全编码之用户输入
  8. Windows SharePoint Services 默认母版页
  9. BufferedReader的ready与readLine使用,以及Premature EOF异常
  10. Javascript前端面试题
  11. [Tjoi2013]最长上升子序列
  12. 什么是IO多路复用
  13. ES系列目录
  14. 2.19 C++友元函数和友元类
  15. 按键精灵如何批量复制文本,再往excel里面一次性粘贴?
  16. mint-ui loadmore组件注意问题
  17. 【剑指offer】栈的压入、弹出序列
  18. Android 实践项目开发一
  19. SPOJ Lexicographical Substring Search 求字典序第k大子串 后缀自动机
  20. git编译安装报错 http-push.c:20:19: 警告:expat.h:没有那个文件或目录

热门文章

  1. 分享知识-快乐自己:2017IDEA破解教程
  2. linkedhashSet和hashSet和TreeSet的区别(转)
  3. elasticsearch-installation
  4. Codeforces Round #394 (Div. 2) 颓废记
  5. uC/OS-II源码分析(一)
  6. bzoj 4753 [Jsoi2016]最佳团体——0/1分数规划
  7. jdk、tomcat如何配置环境变量
  8. VS2008 查找失效怎么办
  9. JVM StackOverflowError vs. OutOfMemoryError
  10. linux下安装mysql的三种方法:rpm包安装、yum安装、源码包安装