题意:有n个航班,被延误了,前面k分钟都不能飞,每个航班延误1分钟需要花费Ci,k+1~k+n时间段内,重新排班,使花费最小,任意航班不能提前飞
思路:,后面这项为常数,考虑每个时间能飞的航班,时间从小到大,花费越大的优先,花费和最小。用一个优先队列把这个时间能飞的航班放进去
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<string>
#include<stdlib.h>
#include<math.h>
#include<vector>
#include<list>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#include<numeric>
#include<functional>
using namespace std;
typedef long long ll;
const int maxn = 300000+5;
struct data
{
ll cost;
int id;
bool friend operator<(const data &x,const data &y)
{
return x.cost < y.cost;
}
};
priority_queue<data> q;
int t[maxn];
ll cost[maxn];
int main(void)
{
int n,k;
while(scanf("%d%d",&n,&k)!=EOF)
{
ll ans = 0;
for(int i = 1; i <= n; i++)
{
scanf("%lld",&cost[i]);
ans -= cost[i] * i;
}
while(!q.empty())
q.pop();
for(int i = 1; i <= k; i++)
q.push((data){cost[i],i});
int time = k+1;
while(!q.empty())
{
if(time <= n) q.push((data){cost[time],time});
data a = q.top();q.pop();
t[a.id] = time;
ans += time * a.cost;
time++;
}
printf("%lld\n",ans);
for(int i = 1; i <= n; i++)
printf("%d%c",t[i],i==n?'\n':' ');
}
return 0;
}