Codeforces Round #433 (Div. 2) C. Planning
来源:互联网 发布:ovid medline数据库 编辑:程序博客网 时间:2024/06/11 15:32
题目大意
飞机延误k分钟,每分钟只能起飞一架,每架飞机每晚一分钟有个代价,求最小代价。
题解
显然前k分钟代价不可避免,直接加入优先队列,其余的先加入优先队列并取出队首。
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<queue>using namespace std;int read(){ char ch=getchar();int f=0; while(ch<'0'||ch>'9') ch=getchar(); while(ch>='0'&&ch<='9') {f=f*10+(ch^48);ch=getchar();} return f;}struct data{ int tim; int val;}a[300005];int t[300005];bool operator < (data x,data y){ return x.val<y.val;}priority_queue<data> q;long long ans;int main(){ int n=read(),k=read(); for(int i=1;i<=k;i++) { a[i].val=read(); data temp; temp.val=a[i].val; temp.tim=i; q.push(temp); } for(int i=k+1;i<=n;i++) { a[i].val=read(); data temp; temp.val=a[i].val; temp.tim=i; q.push(temp); temp=q.top(); q.pop(); t[temp.tim]=i; ans+=1LL*temp.val*(i-temp.tim); } for(int i=n+1;i<=n+k;i++) { data temp; temp=q.top(); q.pop(); t[temp.tim]=i; ans+=1LL*temp.val*(i-temp.tim); } cout<<ans<<endl; for(int i=1;i<=n;i++) printf("%d ",t[i]);}
阅读全文
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)-贪心-C. Planning
- Codeforces Round #433 (2)C:Planning
- Codeforces Round#433 C Planning
- Codeforces Round #433 (Div. 2, 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 #433 (Div. 2) Planning (贪心+并查集)
- Codeforces Round #433 C. Planning(贪心)
- Codeforces Round #433 Div. 2 C
- Codeforces Round #433(Div. 1,based on Olympiad of Metropolises)A Planning B Jury Meeting C Boredom
- 【codeforces】Codeforces Round #370 (Div. 2) C
- Codeforces Round #433 (Div. 2)
- Codeforces Round #433 (Div. 2)
- need_resched 是怎么使用的(ZT)
- php 字符串常用函数总结
- kuangbin 简单搜索 F题
- 数据库分库分表
- apache-ab并发负载压力测试
- Codeforces Round #433 (Div. 2) C. Planning
- Apache服务器和tomcat服务器有什么区别?
- 软件项目绩效——承包制实施经验五则
- 线程--线程的生命周期
- VMware Workstation 与 Device/Credential Guard 不兼容
- 2020年,商业智能分析工具或加入AI技术
- 自定义一个类 可以随机产生大小写字母及数字,并且位数也随机(这里设置的最大位数为10)
- 小程序阻止事件冒泡
- cdh001