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 ;
}

Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) C的更多相关文章

  1. Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises)

    A. Fraction 题目链接:http://codeforces.com/contest/854/problem/A 题目意思:给出一个数n,求两个数a+b=n,且a/b不可约分,如果存在多组满足 ...

  2. Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) D. Jury Meeting(双指针模拟)

    D. Jury Meeting time limit per test 1 second memory limit per test 512 megabytes input standard inpu ...

  3. Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) D

    Country of Metropolia is holding Olympiad of Metrpolises soon. It mean that all jury members of the ...

  4. Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) B

    Maxim wants to buy an apartment in a new house at Line Avenue of Metropolis. The house has n apartme ...

  5. Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) A

    Petya is a big fan of mathematics, especially its part related to fractions. Recently he learned tha ...

  6. Codeforces Round #507 (Div. 2, based on Olympiad of Metropolises) D mt19937

    https://codeforces.com/contest/1040/problem/D 用法 mt19937 g(种子); //种子:time(0) mt19937_64 g(); //long ...

  7. 【Codeforces Round #507 (Div. 2, based on Olympiad of Metropolises) B】Shashlik Cooking

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 翻转一次最多影响2k+1个地方. 如果n<=k+1 那么放在1的位置就ok.因为能覆盖1..k+1 如果n<=2k+1 ...

  8. 【Codeforces Round #507 (Div. 2, based on Olympiad of Metropolises) A】Palindrome Dance

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] i从1..n/2循环一波. 保证a[i]和a[n-i+1]就好. 如果都是2的话填上min(a,b)*2就好 其他情况跟随非2的. ...

  9. Codeforces Round #626 (Div. 2, based on Moscow Open Olympiad in Informatics)

    A. Even Subset Sum Problem 题意 给出一串数,找到其中的一些数使得他们的和为偶数 题解 水题,找到一个偶数或者两个奇数就好了 代码 #include<iostream& ...

随机推荐

  1. java编程实例

    脚本代码: 1. [代码] package com.gufengxiachen.sthreadchatapp;/** * @author GUXIA */import java.io.Buffered ...

  2. mvn使用记录

    1. mvn dependency:copy-dependencies 会导出到targed/dependency 下面 2. mvn dependency:copy-dependencies -Do ...

  3. Java之动态代理简介

    图截于<大话设计模式> Proxy模式是常用的设计模式,其特征是代理类与委托类有同样的接口,代理类主要负责为委托类预处理消息.过滤消息.把消息转发给委托类,以及事后处理消息等. 用户可以更 ...

  4. yum 命令用法

    [root@hdp01 ~]# yum list available |grep ambari  ######列出可安装的程序包ambari-infra-solr.noarch 2.6.1.5-3 a ...

  5. Confd 配置指导

    Quick Start Guide Before we begin be sure to download and install confd. Select a backend confd supp ...

  6. [POI 2000] 公共串

    [题目链接] https://www.lydsy.com/JudgeOnline/problem.php?id=2946 [算法] 建立多串后缀树 对于后缀树上的每个点 , 判断该节点所代表的等价类是 ...

  7. 关闭windows10自动更新

    用windows10的小伙伴们应该都被windows10自动更新这个问题折磨过.那到底要这样禁止windows10的自动更新呢? 百度上有一篇文章写的非常好,并且有配套,大家只要根据步骤操作即可,本人 ...

  8. windows下vs2012用gsoap开发webservice实例

    零:说明 1.本文是根据网上前人经验结合自己动手操作写成,开发工具用的vs2012,gsoap用的是gsoap-2.8: 2.gsoap提供的工具简单介绍 1)wsdl2h.exe:根据WSDL文件生 ...

  9. rman理论(一)

    1) 快照控制文件:开始备份后,RMAN 需要这些信息在备份操作期间保持一致,也就是说RMAN需要一个读取一致的控制文件视图. 除非RMAN 在备份持续时间内锁定控制文件,否则数据库会不断更新控制文件 ...

  10. poj3281Dining——网络流匹配

    题目:http://poj.org/problem?id=3281 网络流做图中的匹配,注意为了限制每头牛只匹配一种食物和一种饮料,要把牛拆成两个点,之间连边权为1的边. 代码如下: #include ...