题意:
你很有可能赶不上飞机,你每拖延一分钟各种飞机要你交一定数额的拖延费,n为飞机数目,k为你要从第k秒开始赶飞机(当然只是单位时间,这里直接用秒了,一秒一辆真快),然后你可以任意选择登机顺序,使得你的拖延费最少,输入的是第i秒开始登机时每拖延一秒的费用,注意只能在登机开始后才能登机,不能提前登机
思路:
用一个优先队列,把可以登机的飞机加入套餐,由于这个费用每一秒增加是固定的,那么我们就选择每秒要交费用最多的那个,然后啪啪啪循环到底就行了
代码:
#include<iostream>
#include<cstring>
#include<stdio.h>
#include<math.h>
#include<string>
#include<stdio.h>
#include<queue>
#include<stack>
#include<map>
#include<vector>
#include<deque>
#include<algorithm>
using namespace std;
#define INF 100861111
#define eps 1e-7
#define lson k*2
#define rson k*2+1
#define ll long long
struct node
{
int t;
int v;
friend bool operator<(node x,node y)
{
return x.v<y.v;
}
}a[300005];
ll vis[300005];
priority_queue<node>q;
int main()
{
int i,j,n,k,d,ans=0,temp;
ll s=0;
node now;
scanf("%d%d",&n,&k);
for(i=1;i<=n;i++)
{
vis[i]=0;
scanf("%d",&a[i].v);
a[i].t=i;
}
while(!q.empty())
q.pop();
d=min(n,k);
d++;
if(d<n)
temp=d;
else
temp=n;
for(i=1;i<=temp;i++)
{
q.push(a[i]);
}
for(i=1;i<=n;i++)
{
now=q.top();
q.pop();
vis[now.t]=d;
s+=(ll)(d-now.t)*now.v;
d++;
if(temp<n)
{
q.push(a[temp+1]);
}
if(d<n)
temp=d;
else
temp=n;
}
printf("%lld\n",s);
printf("%lld",vis[1]);
for(i=2;i<=n;i++)
printf(" %lld",vis[i]);
printf("\n");
return 0;
}