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 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
随机推荐
- mysql 5.7 Group Replication
MySQL 组复制实现了基于复制协议的多主更新(单主模式). 复制组由多个 server成员构成,并且组中的每个 server 成员可以独立地执行事务.但所有读写(RW)事务只有在冲突检测成功后才会提 ...
- EF数据迁移
在项目中使用Entity Framework的Code First模式,进行数据迁移时,Migration文件夹中存放的是每一次Entity的修改如何同步到数据的操作方法,每个文件中都只有Up和Dow ...
- 随机函数rand()和srand()
C++中随机函数rand()和srand()的用法 一.rand() 函数名: rand 功 能: 随机数发生器 用 法: int rand(void); 所在头文件: ...
- Js -----后台json数据,前端生成下载text文件
需要引入 <script src="/assets/libs/single_file/jquery.min.js"></script> <script ...
- [HTTP]Etag的工作流程
1. 浏览器首次访问该资源时,web服务器返回资源的同时,响应报文头携带ETag标签: 2. 浏览器将保存该Etag标签的值: 3. 当浏览器发起下一次请求,请求报文头将会携带 If-None-Mat ...
- Spring与Quartz实现定期任务
<!-- 任务调度测试实现一 : 自定义的任务对象com.bocloud.equipment.test.ExampleJob 必须继承QuartzJobBean类,实现抽象方法executeIn ...
- 35)django-验证码
一:验证码原理 第一次访问GET,后台: 1.创建一张图片 2.在图片中写入随机字符串 3.将图片写到制定文件 4.打开指定目录文件,读取内容 5.把生成的验证码保存在session中 6. 通过Ht ...
- 《深入理解Oracle 12c数据库管理(第二版)》PDF
一:下载获取位置: 二:本书图样: 三:本书目录: 图书目录: 第1章 安装Oracle 1.1 了解OFA 1.1.1 Oracle清单目录 1.1.2 Oracle基础目录 1.1.3 Oracl ...
- ssd.pytorch
https://towardsdatascience.com/learning-note-single-shot-multibox-detector-with-pytorch-part-1-38185 ...
- maven项目使用log4j
日志是应用软件中不可缺少的部分,Apache的开源项目 log4j 是一个功能强大的日志组件,提供方便的日志记录. 1.maven项目在pom.xml导入log4j依赖: <dependency ...