Codeforces 853 A. Planning

传送门:https://codeforces.com/problemset/problem/853/A

题目大意:
这个飞机场上有n架飞机,按计划从第一天开始,每天飞出一架,但飞机场比较任性,它前面k天不想让飞机走。但它不让它们走又得赔违约金,每架飞机每迟一天要ai的钱,于是,架不住肉疼,它想安排一下飞行顺序,使得每天依然只让一架走,但最后亏的钱最少。

主要想法:
这个肯定要用到排序,而且每次肯定用最大的数,这个让我不禁想起了优先队列。好的,大的方向有了,我们还得注意,飞机没事不会提前飞,在这个前提下,我们只要让违约金贵的尽量少拖延,于是,我们就计算在第k+i天哪些飞机可以飞,然后选出最贵的就可以了。

 代码实现:
#include <bits/stdc++.h>using namespace std;
struct node
{int x,y;bool operator < (const node & a)const{return x<a.x;}
}b;int main()
{int n,k;long long ans=(long long)0;cin>>n>>k;priority_queue<node>a;vector<int>d(n);for(int i=0;i<k;++i){int c;scanf("%d",&c);b.x=c;b.y=i;a.push(b);}for(int i=k;i<n;++i){int c;scanf("%d",&c);b.x=c;b.y=i;a.push(b);ans+=(long long)a.top().x*(i-a.top().y);d[a.top().y]=i+1;a.pop();}for(int i=n;i<n+k;++i){ans+=(long long)a.top().x*(i-a.top().y);d[a.top().y]=i+1;a.pop();}cout<<ans<<endl;for(int i=0;i<n;i++)printf("%d ",d[i]);return 0;
}

Codeforces 853 A. Planning相关推荐

  1. Codeforces 854 C Planning 贪心 最大堆

    题目链接: https://vjudge.net/problem/CodeForces-854C 题目描述: 有n架飞机,第i架飞机原本计划在第i分钟起飞,可是由于某种原因整个机场前k分钟是不能起飞的 ...

  2. CodeForces - 1321B Journey Planning(思维)

    题目链接:点击查看 题目大意:给出一个长度为 n 的数列,规定本题中的上升子序列必须满足两个条件: a[ j ] < a[ i ] a[ i ] - a[ j ] = i - j 问累加和最大的 ...

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

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

  4. Codeforces Round #853 (Div. 2) C. Serval and Toxel‘s Arrays【统计次数,算贡献】

    链接 传送门 分析 这道题想法其实很简单,样例的计算方法一定要看懂.以样例1为例,根据他的操作方法可以得到两个新的数组,和一个原来的数组,总共三个数组. 1 2 3 4 2 3 4 5 3 他们两两配 ...

  5. 【Codeforces Round #853 (Div. 2)】C. Serval and Toxel‘s Arrays【题解】

    题目 Toxel likes arrays. Before traveling to the Paldea region, Serval gave him an array a a a as a gi ...

  6. Codeforces Round #433 (Div. 2, based on Olympiad of Metropolises)

    A. Fraction 题目链接:http://codeforces.com/contest/854/problem/A 题目意思:给出一个数n,求两个数a+b=n,且a/b不可约分,如果存在多组满足 ...

  7. Codeforces Round #343 (Div. 2) A. Far Relative’s Birthday Cake 水题

    A. Far Relative's Birthday Cake 题目连接: http://www.codeforces.com/contest/629/problem/A Description Do ...

  8. Codeforces Round #625 (Div. 2, based on Technocup 2020 Final Round)【A、B、C题】

    A. Contest for Robots 签到题,注意特判即可. #include <bits/stdc++.h> using namespace std; const int N=11 ...

  9. codeforces Round 21 808E. Selling Souvenirs 【dp好题】

    codeforces Round 21 808E. Selling Souvenirs [dp好题] E. Selling Souvenirs time limit per test 2 second ...

  10. CodeForces 375D Tree and Queries

    传送门:https://codeforces.com/problemset/problem/375/D 题意: 给你一颗有根树,树上每个节点都有其对应的颜色,有m次询问,每次问你以点v为父节点的子树内 ...

最新文章

  1. Windows10快捷应用指令
  2. oracle求sql的cpu贡献率,oracle 实时查询最耗CPU资源的SQL语句
  3. 《Linux From Scratch》第三部分:构建LFS系统 第六章:安装基本的系统软件- 6.2. 准备虚拟内核文件系统...
  4. hdu 2669 Romantic
  5. 25个出众的Web表单范例
  6. python通过tkinter和json界面库实现考研知识点统计
  7. 学习笔记-java编程-交通灯管理器设计流程。
  8. python画环形图_用Python把图做的好看点:用Matplotlib画个环形图
  9. 【Arthas】Arthas Command处理流程
  10. java线程的小问题与回答
  11. python抓包与解包_python 抓包与解包
  12. 据说,上次获奖的同学拿了奖金泡了班花还get到了2个offer
  13. Android UI开发:AlertDialog对话框
  14. HDLC 和PPP 的应用
  15. ExcelWriter 导出excel
  16. 第二季:9.生产环境服务器变慢,诊断思路和性能评估谈谈?【Java面试题】
  17. 基于遗传算法在机器人路径规划中的应用研究(Matlab代码实现)
  18. 柱状图怎么添加数据python_Python数据可视化:如何用Matplotlib创建柱状图
  19. 技术干货 | 录屏采集实现教程 —— Windows桌面端
  20. CAS单点登录学习笔记二之部署CAS Server

热门文章

  1. dota2自定义地图服务器,RPG DOTA2 自定义地图制作指南——构建模型
  2. 拼多多商品详情页API接口、拼多多APP详情API接口、拼多多商品销量API接口、拼多多商品列表API接口、拼多多详情API接口
  3. UWB室内定位系统,你知道几分
  4. 【Python】openpyxl设置excel的表格边框内外边框不同处理
  5. c语言作业汽车加速,C语言求车速
  6. 嵌入式学习--1线协议(以ds18b20为例)
  7. linux终端清除命令,ubuntu清除命令行记录
  8. VO、DO、DTO、PO是什么
  9. edge浏览器开启夜间模式
  10. 感冒会引发腺样体肥大吗?