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

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 费用最高的优先讨论

复制代码
 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 long long n,k;
 4 struct Node{
 5     long long num;
 6     int pos;
 7 }node[301000];
 8 bool Sort(Node x,Node y){
 9     if(x.num==y.num){
10         return x.pos<y.pos;
11     }
12     return x.num>y.num;
13 }
14 long long sum;
15 set<int>Se;
16 int X[301000];
17 int main(){
18     scanf("%d%d",&n,&k);
19     for(int i=1;i<=n;i++){
20         scanf("%d",&node[i].num);
21         node[i].pos=i;
22         Se.insert(i+k);
23     }
24     sort(node+1,node+1+n,Sort);
25     for(int i=1;i<=n;i++){
26        // cout<<node[i].num<<"A "<<node[i].pos<<endl;
27         int ans=*Se.lower_bound(node[i].pos);
28         sum+=(ans-node[i].pos)*node[i].num;
29         X[node[i].pos]=ans;
30         Se.erase(ans);
31     }
32     cout<<sum<<endl;
33     for(int i=1;i<=n;i++){
34         cout<<X[i]<<" ";
35     }
36     return 0;
37 }
复制代码

 

posted @   樱花落舞  阅读(221)  评论(0编辑  收藏  举报
编辑推荐:
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
· 开发者必知的日志记录最佳实践
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 从HTTP原因短语缺失研究HTTP/2和HTTP/3的设计差异
· 三行代码完成国际化适配,妙~啊~
历史上的今天:
2016-09-07 Educational Codeforces Round 1 A
点击右上角即可分享
微信分享提示