题意

给出飞机单位晚点时间代价和原定起飞时间,现在前k分钟不能起飞,求付出的最小代价和起飞顺序

思路

构造两个优先队列q1,q2,q1按时间顺序,q2按代价顺序,初始将所有飞机入q1,将时间在k前的飞机从q1加入q2,然后按时间顺序取出q1加入q2,同时从q2取出代价最大的加入答案

代码

#include<bits/stdc++.h>
using namespace std;
inline int read(){
int x = ,f= ; char ch = getchar();
while(ch<'' || ch>'') {if(ch == '-') f=-;ch = getchar();}
while(ch>=''&&ch<='') {x = x*+ch-'';ch = getchar();}
return x*f;
}
int n, k;
long long ans;
struct F{
long long t;
long long v;
int ans;
F(){}
F(int a,int b){
t = a, v = b;
}
}f[];
struct CMPT{
bool operator()(const F& a, const F& b){
return a.t>b.t;
}
};
struct CMPV{
bool operator()(const F& a, const F& b){
return a.v<b.v;
}
};
priority_queue<F, vector<F>, CMPT> qt;
priority_queue<F, vector<F>, CMPV> qv;
int main(){
scanf("%d%d",&n,&k);
for(int i = ;i<=n;i++) f[i] = F(i, read()), qt.push(f[i]);
while(qt.top().t<=k && !qt.empty()){
qv.push(qt.top());
qt.pop();
}
for(int i = k+;i<=k+n;i++){
if(!qt.empty()) qv.push(qt.top()), qt.pop();
ans += (i-qv.top().t)*qv.top().v, f[qv.top().t].ans = i;
qv.pop();
}
printf("%I64d\n",ans);
for(int i = ;i<=n;i++) printf("%d%s",f[i].ans,(i == n?"\n":" "));
return ;
}

Codeforces 853A Planning的更多相关文章

  1. CodeForces - 853A Planning (优先队列,贪心)

    Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are n ...

  2. (codeforces 853A)Planning 贪心

    Helen works in Metropolis airport. She is responsible for creating a departure schedule. There are n ...

  3. codeforces 854C.Planning 【贪心/优先队列】

    Planning time limit per test 1 second memory limit per test 512 megabytes input standard input outpu ...

  4. codeforce 853A Planning

    题目地址:http://codeforces.com/problemset/problem/853/A 题目大意: 本来安排了 n 架飞机,每架飞机有 ci 的重要度, 第 i 架飞机的起飞时间为 i ...

  5. Codeforces 854C Planning 【贪心】

    <题目链接> 题目大意: 表示有n架飞机本需要在[1,n]时间内起飞,一分钟只能飞一架.但是现在[1,k]时间内并不能起飞,只能在[k+1,k+n]内起飞.ci序号为i的飞机起飞延误一分钟 ...

  6. Codeforces 854C Planning(贪心+堆)

    贪心:让代价大的尽量移到靠前的位置. 做法:先让前k个数加进堆里,枚举k+1~n+k,每次把新元素加进堆后找到最大代价放在当前位置即可. #include<bits/stdc++.h> # ...

  7. Planning CodeForces - 854C

    Planning CodeForces - 854C 题意:有n架航班,第i架原先的时候是在第i分钟起飞的.现在前k分钟无法有飞机起飞,因此需要调整安排表,延后飞机起飞.仍然要求每一分钟只有一架飞机起 ...

  8. Codeforces div2 #499 B. Planning The Expedition 大水题

    已经是水到一定程度了QAQ- Code: #include<cstdio> #include<algorithm> #include<cstring> using ...

  9. 【Codeforces Round #433 (Div. 2) C】Planning

    [链接]h在这里写链接 [题意] 让你确定ti,使得∑(ti-i)*gi最小,其中ti∈[k+1..k+n],且每个ti都不能一样. 且ti>=i必须成立. [题解] 分解一下成为∑ti*gi ...

随机推荐

  1. HTTP中的请求头和响应头属性解析

    HTTP中的请求头和响应头属性解析 下面总结一下平时web开发中,HTTP请求的相关过程以及重要的参数意义 一次完整的HTTP请求所经历的7个步骤 说明:HTTP通信机制是在一次完整的HTTP通信过程 ...

  2. ClientDataSet中修改,删除,添加数据和Delta属性

    ClientDataSet中使用Post提交变更的数据时,实际上并没有更新到后端数据库中,而是提交到了由DataSnap管理的数据缓冲区中.当使用了ClientDataSet.ApplyUpDates ...

  3. Vue.js学习TodoMVC小Demo

    实现效果如下: 把玩了添加和删除功能,代码如下: index.html: <!doctype html> <html lang="en"> <head ...

  4. laravel原生sql

    转自:https://www.cnblogs.com/zouzhe0/p/6307077.html DB::insert(, ']); $user = DB::]); //我们还 可以看到在执行查询的 ...

  5. Python3之定制类

    看到类似的__slots__这种形如__xxx__的变量或者函数名就要注意,这些在Python中是有特殊用途的 Python中还有许多有特殊用途的函数,可以帮助我们定制类 __str__ 先定义一个S ...

  6. golang 日志模块(log)

    log 日志 log 模块可以自定义log 对象, 也可以使用log默认对象的日志方法 func New 创建log对象 func New(out io.Writer, prefix string, ...

  7. WebGL学习之HDR与Bloom

    原文地址:WebGL学习之HDR与Bloom 什么是HDR HDR (High Dynamic Range,高动态范围),在摄影领域,指的是可以提供更多的动态范围和图像细节的一种技术手段.简单讲就是将 ...

  8. JPEG2000开发SDK及其特点

    JPEG2000开发SDK及其特点 声明:引用请注明出处http://blog.csdn.net/lg1259156776/ 说明:JPEG2000被开发来取代JPEG,但因为大量核心算法被专利注册, ...

  9. Qt598x64vs2017.跨线程传递std::string

    1.Qt编译的时候 提示 str::string 需要在main(...)中注册什么的(大概是这个意思,记不清了),于是 在main(...)中调用了 “qRegisterMetaType<st ...

  10. 高级UI-RecyclerView间隔线添加

    上文讲到了RecyclerView的简单使用,知道RecycleView是怎么使用的了,那么这一节将基于上一届的内容继续改进,在ListView中很轻松就能实现的间隔线,在RecycleView中也需 ...