Codeforces Round #433 (Div. 2)-贪心-C. Planning
来源:互联网 发布:足彩数据 编辑:程序博客网 时间:2024/06/06 20:34
http://codeforces.com/contest/854/problem/C
一些飞机本来是有顺序的,顺序为i,后来他们都要延时k分钟,
问你怎样安排才能让他们 损失的钱最少
(给你一个数组,说明他们每比开始预计的时间少,就要损失多少钱。)
又复习了一遍 优先队列。。。
这题有点赤裸裸。。
因为题中有一个限制条件,飞机不能比他们预定的时间还早。。
所以 我们维护一个 优先队列,开始放入 1-k的。然后找到一个最大的。
pop掉,然后再一个一个加。到了边界就不加 只pop。
用一个数组记录一下时间,完事。
#include <bits/stdc++.h>using namespace std;typedef long long ll;const int maxn=3e5+300;struct node{ int v,id; node(int _a,int _b){v=_a,id=_b;}; friend bool operator<(node a,node b){ return a.v<b.v; };};vector<pair<int,int> >v;priority_queue<node>q;int num[maxn];int main(){ int m,n,aa; while(~scanf("%d%d",&m,&n)){ v.clear(); v.push_back(make_pair(0,0)); for(int i=1;i<=m;i++){ scanf("%d",&aa); v.push_back(make_pair(aa,i)); } int t=n+1; for(int i=1;i<=n+1;i++){ q.push(node(v[i].first,v[i].second)); } int tim=n+1; for(int i=1;i<=m;i++){ node u=q.top(); q.pop(); num[u.id]=t; t++; tim++; if(tim<=m) q.push(node(v[tim].first,tim)); // cout<<v[tim].first<<" "<<tim<<endl; } ll ans=0; for(int i=1;i<=m;i++){ ans+=1ll*(num[i]-i)*v[i].first; } printf("%lld\n",ans); for(int i=1;i<=m;i++){ if(i==1) printf("%d",num[i]); else printf(" %d",num[i]); } printf("\n"); } return 0;}
阅读全文
0 0
- Codeforces Round #433 (Div. 2) C. Planning(贪心)
- Codeforces Round #433 (Div. 2)-贪心-C. Planning
- Codeforces Round #433 (Div. 2) C. Planning
- Codeforces Round #433 (Div. 2) C. Planning
- Codeforces Round #433 (Div. 2) Planning (贪心+并查集)
- Codeforces Round #433 (Div. 2, C. Planning (贪心+简单实现)
- Codeforces Round #433 C. Planning(贪心)
- Codeforces Round #433 (Div. 2 C. Planning(优先队列)
- Codeforces Round #433 (2)C:Planning
- Codeforces Round#433 C Planning
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) C Planning
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises)C. Planning
- Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises) C. Planning(并查集)
- Codeforces Round #311 (Div. 2) C 贪心
- Codeforces Round #363 (Div. 2)-C--贪心
- Codeforces Round #370 (Div. 2) C 贪心
- Codeforces Round #375 (Div. 2) C (贪心)
- Codeforces 854C. Planning 贪心
- 关于vim复制剪贴粘贴命令的总结
- 如何安装使用web前端的包管理器bower
- Spark Streaming(上)--实时流计算Spark Streaming原理介绍
- 阿里设计师带你探讨UxD设计是什么?
- 【Cumputer】《第一次机房收费系统》总结四 循环结构运用 (全部下机、实时结算、导出Excel表)
- Codeforces Round #433 (Div. 2)-贪心-C. Planning
- 获取鼠标单击的位置
- 自动化发布技巧一
- 使用IntelliJ IDEA进行远程调试
- SpringBoot学习-(十五)SpringBoot热部署
- OpenGL 纹理单元的使用步骤详解
- java 时间日期 详解
- 图像反转
- AutoGridView:轻松实现微信朋友圈九宫格