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 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
随机推荐
- Zabbix3.2监控Windows的内存使用百分比并在内存使用率超过85%的时候触发报警
内存使用率key:vm.memory.size[pused]
- 在Centos7 上安装SVN
https://blog.csdn.net/crossangles_2017/article/details/78553266 1.安装 使用yum安装非常简单: yum install subver ...
- Vue-cli 搭建web服务介绍
Node.js 之 npm 包管理 - Node.js 官网地址:点我前往官网 - Node.js 中文镜像官网: 点我前往```` Node.js 是一个基于 Chrome V8 引擎的 JavaS ...
- 彻底删除mysql服务(清理注册表)
前言 由于安装某个项目的执行文件,提示要卸载MySQL以便它自身MySQL安装,然后我禁用了MYSQL服务,再把这个文件夹删除后,发现还是提示请卸载MYSQL服务. ----------------- ...
- [PHP]session的一些要点
一.session_start([array $options=array()]) 1.只能在输出http头前启动此函数,因为如果需要改写sessid的键和值,需要在http报文头发出前就开始定义了: ...
- jquery中的attr与prop的区别,什么时候用attr,什么时候用prop
只要有 Boolean() 属性的,简单说就是具有true 和 false 两个属性的属性,如 checked, selected 或者 disabled 使用prop(),(其实这些都是表单类的), ...
- vue 之 引入elementUI(两步走)
1.npm 引入elementUI npm i element-ui -S 2.在main.js文件中全局引入 import ElementUI from 'element-ui' import 'e ...
- Centos7 设置静态IP地址
一: 修改网卡配置文件(操作前先备份一下该文件),/etc/sysconfig/network-scripts/ 具体操作如下: 1:进入修改目录 [root@localhost ~]# clear ...
- Confluence 6 的小型文字档案(Cookies)
这个页面列出了存储在 Confluence 用户浏览器中的小型文字档案(Cookies)内容.这些内容是由 Confluence 自己创建的.这个页面不会列出由 Confluence 安装的第三方插件 ...
- libopencv_highgui.so.2.4.9:对‘TIFFReadRGBAStrip@LIBTIFF_4.0’未定义的引用
make之前加上sudo su重新make即可 http://blog.csdn.net/cfyzcc/article/details/52981467