zoukankan      html  css  js  c++  java
  • 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 }
  • 相关阅读:
    JQuery优化之 -- 正确使用选择器
    Vue计算属性methords 与 computed 的区别
    HTML中常用字符实体
    SQL复习(w3school)笔记
    AndroidStudio中使用AndroidAnnotations时,build.gradle的配置
    JAVA的第一次作业
    input标签submit属性,用CSS控制样式时高度不好控制的解决办法
    微信小程序开发五:案例实践
    微信小程序开发四:接口
    微信小程序开发三:组件
  • 原文地址:https://www.cnblogs.com/yinghualuowu/p/7491281.html
Copyright © 2011-2022 走看看