Codeforces 746F Music in Car
用两个Set维护一下尺取的过程。
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mk make_pair
#define PLL pair<LL, LL>
#define PLI pair<LL, int>
#define PII pair<int, int>
#define SZ(x) ((int)x.size())
#define ull unsigned long long using namespace std; const int N = 2e5 + ;
const int inf = 0x3f3f3f3f;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const int mod = 1e9 + ;
const double eps = 1e-;
const double PI = acos(-); int n, w, k, a[N], t[N];
bool flag[N]; set<PII> Set1;
set<PII> Set2; int main() {
scanf("%d%d%d", &n, &w, &k);
for(int i = ; i <= n; i++) scanf("%d", &a[i]);
for(int i = ; i <= n; i++) scanf("%d", &t[i]);
int now = , tmp = , ans = ;
for(int i = , j = ; i <= n; ++i){
now += ( + t[i]) >> ;
tmp += a[i];
if(Set1.size() < w){
Set1.insert(mk(t[i] >> , i));
flag[i] = true;
}else{
if((*Set1.begin()).fi < (t[i] >> )){
PII tt = *Set1.begin();
Set1.erase(Set1.begin());
now += tt.fi;
flag[tt.se] = false;
Set1.insert(mk(t[i] >> , i));
flag[i] = true;
Set2.insert(tt);
}
else{
now += t[i] >> ;
Set2.insert(mk(t[i] >> , i));
}
}
while(now > k){
if(flag[j]){
now -= (t[j] + ) >> ;
Set1.erase(mk(t[j] >> , j));
while(Set2.size() && (*Set2.rbegin()).se < j) Set2.erase(*Set2.rbegin());
if(Set2.size()){
PII tt = *Set2.rbegin();Set2.erase(*Set2.rbegin());
now -= tt.fi;
Set1.insert(tt);
flag[tt.se] = true;
}
}
else{
now -= t[j];
}
tmp -= a[j];
++j;
}
ans = max(ans, tmp);
}
printf("%d\n", ans);
return ;
} /*
*/
Codeforces 746F Music in Car的更多相关文章
- Music in Car CodeForces - 746F
Music in Car CodeForces - 746F 题意很难懂啊... 题意:http://blog.csdn.net/a838502647/article/details/74831793 ...
- Music in Car CodeForces - 746F (贪心,模拟)
大意: n首歌, 第$i$首歌时间$t_i$, 播放完获得贡献$a_i$, 最多播放k分钟, 可以任选一首歌开始按顺序播放, 最多选w首歌半曲播放(花费时间上取整), 求贡献最大值. 挺简单的一个题, ...
- Codeforces Round #386 (Div. 2) 746F(set的运用)
题目大意 给出一个歌单(有n首歌),每个歌都有愉悦值和时间,你可以选择从第x首歌开始听(也就是选择连续的一段),并且你可以选择w首歌让它的时间减半,限制时间为k,求最大的愉悦值 首先我们需要贪心一下, ...
- python爬虫学习(5) —— 扒一下codeforces题面
上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...
- 【Codeforces 738D】Sea Battle(贪心)
http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...
- 【Codeforces 738C】Road to Cinema
http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...
- 【Codeforces 738A】Interview with Oleg
http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- CodeForces - 274B Zero Tree
http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
随机推荐
- Kendo ui 入门知识点
1. Kendo的继承 varPerson= kendo.Class.extend({...}); var person = new person(); var Parent = kendo.Clas ...
- druid:java代码创建连接池
PropertiesDB 是一个读取配置文件的类,也可以不用,每个参数直接用String代替. public DataSource dataSource(PropertiesDB properties ...
- shell脚本学习系列之一---入门
参考:http://me.52fhy.com/shell-book/ 待后续整理...
- GridView的stretchMode属性
stretchMode属性值的作用是设置GridView中的条目以什么缩放模式去填充剩余空间.参数stretchMode 可选值为:none,spacingWidth,columnWidth, spa ...
- 使用VW时,图片的问题
在项目中,使用了VW适配,给图片直接设置了width和height,浏览器模拟正常,在手机上就不显示 解决办法是:在图片外面包一层div,设置width和height,然后图片设置width:100% ...
- vue——router
1.不同界面传参 <router-link :to="{path:'地址'},query:{name:val}">, 其它界面获取: this.$route.query ...
- Confluence 6 从外部小工具中注册访问
希望从 Confluence 中删除一个小工具,你可以选择小工具边上的 URL ,然后单击删除(Delete). 如果你希望取消订阅一个应用的小工具,你需要删除整个订阅.你不能仅仅删除你订阅中的某一个 ...
- ES6之Set与Map加深理解
Set 类似于数组,但是成员的值都是唯一的,没有重复的值,有序. Set函数可以接受一个数组(或者具有 iterable 接口的其他数据结构)作为参数,用来初始化. 用途 数组去重: [...new ...
- Python基础之多态与多态性
切记:不要将多态与多态性这二者混为一谈,只要分开,就会很明朗了. 一.多态 多态指的是一类事物有多种形态,(一个抽象类有多个子类,因而多态的概念依赖于继承). 比如:动物分为人类.狗类.猪类(在定义角 ...
- swoole 简介