题面:

传送门

思路:

一眼看得,这是贪心【雾】

实际上,我们要求的答案就是sigma(ci*(ti-i))(i=1~n),这其中sigma(ci*i)是确定的

那么我们就要最小化sigma(ci*ti)

所以在新的每一秒,就把这一秒开始可以起飞的飞机中,cost最大的那一个拿出来,让他起飞就可以了

证明:

设最大的为m,我们取得另一个为n

那么n*ti+m*(ti+1) >= n*(ti+1)+m*ti

所以取m最好

这个过程用堆实现,懒得手打了,就用了priority_queue

Code:

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
inline int read(){
int re=,flag=;char ch=getchar();
while(ch>''||ch<''){
if(ch=='-') flag=-;
ch=getchar();
}
while(ch>=''&&ch<='') re=(re<<)+(re<<)+ch-'',ch=getchar();
return re*flag;
}
struct flight{
int t,cost;
}a[];
inline bool operator < (flight l,flight r){
return l.cost<r.cost;
}
priority_queue<flight>q;
int n,k;long long tot=;
int ans[];
int main(){
int i;flight tmp;
n=read();k=read();
for(i=;i<=n;i++) a[i].t=i,a[i].cost=read();
for(i=;i<=k;i++) q.push(a[i]);
for(i=k+;i<=k+n;i++){
if(i<=n) q.push(a[i]);
tmp=q.top();q.pop();
ans[tmp.t]=i;tot+=(i-tmp.t)*1ll*tmp.cost;
}
printf("%lld\n",tot);
for(i=;i<=n;i++) printf("%d ",ans[i]);
}

cf 853 A planning [贪心]的更多相关文章

  1. CF 115B Lawnmower(贪心)

    题目链接: 传送门 Lawnmower time limit per test:2 second     memory limit per test:256 megabytes Description ...

  2. CF Soldier and Badges (贪心)

    Soldier and Badges time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  3. CF Anya and Ghosts (贪心)

    Anya and Ghosts time limit per test 2 seconds memory limit per test 256 megabytes input standard inp ...

  4. cf 853 D Michael and Charging Stations [dp]

    题面: 传送门 思路: 看到题目,第一思路是贪心,但是我很快就否决掉了(其实分类贪心也可以做) 然后就想,贪心不能解决的状态缺失,是否可以用dp来解决呢? 事实证明是可以的 我们设dp[i][j]表示 ...

  5. #433 Div2 Problem C Planning (贪心 && 优先队列)

    链接 : http://codeforces.com/contest/854/problem/C 题意 : 有 n 架飞机需要分别在 1~n 秒后起飞,允许起飞的时间是从 k 秒后开始,给出每一架飞机 ...

  6. CF 1082E Increasing Frequency(贪心)

    传送门 解题思路 贪心.对于一段区间中,可以将这段区间中相同的元素同时变成\(c\),但要付出的代价是区间中等于\(c\)的数的个数,设\(sum[i]\)表示等于\(c\)数字的前缀和,Max[i] ...

  7. (codeforces 853A)Planning 贪心

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

  8. cf 12C Fruits(贪心【简单数学】)

    题意: m个水果,n个价格.每种水果只有一个价格. 问如果给每种水果分配价格,使得买的m个水果总价格最小.最大. 输出最小值和最大值. 思路: 贪心. 代码: bool cmp(int a,int b ...

  9. CF 161B Discounts(贪心)

    题目链接: 传送门 Discounts time limit per test:3 second     memory limit per test:256 megabytes Description ...

随机推荐

  1. Python求列表中某个元素的下标

    一.求列表中某个元素的下标 def findindex(org, x, pos=-1): counts = org.count(x) #先求出org中包含x的个数 if counts == 0: #个 ...

  2. 使用pip 提示UnicodeDecodeError: 'ascii' codec can't decode解决方法

    python目录 Python27\Lib\site-packages 建一个文件sitecustomize.py 内容写: import sys sys.setdefaultencoding('gb ...

  3. kubernetes-ingress(十)

    ingress https://kubernetes.io/docs/concepts/services-networking/ingress/ pod与ingress的关系 •通过label-sel ...

  4. C#继承机制 多级继承

    一些面向对象语言允许一个类从多个基类中继承,而另一些面向对象语言只允许从一个类继承,但可以随意从几个接口或纯抽象类中继承. 只有C++支持多级继承,许多程序员对此褒贬不一.多级继承常会引起继承来的类之 ...

  5. {"errmsg":"invalid weapp pagepath hint: [IunP8a07243949]","errcode":40165}微信的坑

    使用微信官方文档,发送请求会报错--   pagepath无效! 正确修改-- 将标红的pagepath改成 page与上面相同即可

  6. MyISAM 和 InnoDB 的区别与优化

    MyISAM 和 InnoDB 的基本区别 1.InnoDB不支持FULLTEXT类型的索引. 2.InnoDB 中不保存表的具体行数,也就是说,执行select count(*) from tabl ...

  7. 关于在namanode上编写脚本控制DataNode的...

    脚本如下:(我的虚拟机名字分别为:wang201 wang 202 wang 203 wang 204) params=$@ i= ; i <= ; i++)) ; do echo ====== ...

  8. Codeforces Round #271 (Div. 2) D Flowers【计数dp】

    D. Flowers time limit per test 1.5 seconds memory limit per test 256 megabytes input standard input ...

  9. poj 3273 分期问题 最大化最小值

    题意:将N个账款分给城M个财务期,使得每个分期账款和的值最大? 思路: 每次mid为分期账款 如果分期次数小于m说明mid太大,减上限  反正 增下限 开始下限设为 最大值 上限设为和 解决问题的代码 ...

  10. 笔记-python-standard library-8.1 data types-datetime

    笔记-python-standard library-8.1 data types-datetime 1.      Datatimes 本章节内容为日期和时间处理类和方法. 1.1.    date ...