[codeforces] 854C. Planning(优先队列)
来源:互联网 发布:centos nat 配置 编辑:程序博客网 时间:2024/06/11 09:13
[codeforces] 854C. Planning(优先队列)
题目链接:
C. Planning
题目大意:
有
数据范围:
解题思路:
对于任意两个飞机a, b如果后者的花费大于前者, 那么两个交换位置肯定更优, b再跟前面的比往前比较, 直到不再比前面的飞机花费大了或者b到了原来的起飞时间(不能更早了)。
有了这个思路之后, 首先能在第一秒起飞的是1到k + 1号飞机, 因为k + 2号飞机最早最早也只能第二秒起飞。 这样我们可以用优先队列维护k + 1个飞机, 每次起飞(弹出)最大的, 然后再放入下一个飞机。
代码:
/******************************************** *Author* :ZZZZone *Created Time* : 四 9/ 7 12:56:25 2017 *Ended Time* : 四 9/ 7 13:17:00 2017*********************************************/#include<cstdio>#include<cstring>#include<cmath>#include<algorithm>#include<cstdlib>#include<queue>using namespace std;const int MaxN = 3e5;typedef long long LL;typedef pair<int, int> PII;int ans[MaxN + 5], c[MaxN + 5];priority_queue<PII>q;int n, k;int main(){ while(~scanf("%d %d", &n, &k)){ for(int i = 1; i <= n; i++){ scanf("%d", &c[i]); } for(int i = 1; i <= k + 1; i++) q.push(make_pair(c[i], i)); LL tot = 0; int xx = k + 1; for(int i = k + 2; i <= n; i++){ int now = q.top().second; ans[now] = xx++; tot += 1LL * (ans[now] - now) * c[now]; q.pop(); q.push(make_pair(c[i], i)); } while(!q.empty()){ int now = q.top().second; ans[now] = xx++; tot += 1LL * (ans[now] - now) * c[now]; q.pop(); } printf("%lld\n", tot); for(int i = 1; i <= n; i++) printf("%d ", ans[i]); } return 0;}
标签:codeforces 优先队列
阅读全文
0 0
- [codeforces] 854C. Planning(优先队列)
- Codeforces 854 C Planning(优先队列+贪心)
- Codeforces Round #433 (Div. 2 C. Planning(优先队列)
- Codeforces 854C. Planning 贪心
- Codeforces 853A Round#433 Div2C & Div1A Planning:优先队列或堆或排序
- CodeForces 140C 贪心+优先队列
- CodeForces 137C【贪心+优先队列】
- codeforces 45c dancing lessons(优先队列)
- Codeforces Round#433 C Planning
- Codeforces 854C Planning【贪心+并查集】
- 【映射 && 优先队列】CodeForces
- 优先队列 CodeForces
- Codeforces Round #357 (Div. 2)-C. Heap Operations(优先队列)
- [CodeForces - 140C New Year Snowmen] 贪心 + STL 优先队列
- Codeforces Alpha Round #20 C. Dijkstra?(优先队列优化)
- 【codeforces 681C】【优先队列+模拟】 Heap Operations
- CodeForces 140C - New Year Snowmen(优先队列)
- 【Codeforces 747 C Servers 】+ 思维 或 优先队列
- 一个员工都不想招,我还能创业成功吗?
- 数据库的脏读、不可重复读、幻读以及不可重复读和幻读的区别
- THREE.Euler()欧拉角
- 九度[1042]-Coincidence
- DL&ML基础学习一
- [codeforces] 854C. Planning(优先队列)
- 使用python操作mysql数据库
- 机器学习简介 | GAIR大讲堂
- 笔记7 | 淡入淡出动画TransitionDrawable
- CSS垂直水平居中8种方法
- web应用国际化
- 合法括号子段
- java第一次课时
- 数组及排序算法