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 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...
随机推荐
- 行为驱动:BDD框架之Cucumber初探
1.cucumber cucumber早在ruby环境下应用广泛,作为BDD框架的先驱,cucumber后来被移植到了多平台,简单来说cucumber是一个测试框架,就像是juint或是rspec一样 ...
- 请在微信客户端打开链接 html
1 前言 有时候,需要链接只能在微信上打开,如果不是,则提示请在微信客户端打开链接的字眼的网页,网页代码如下:(这个是网页应用授权时,非微信上打开,就会出现,然后把它单独拿出来了) 2 代码 < ...
- 执行原生SQL语句的方式
原生sql语句 cursor方法:from api.models import *from django.db import connection,connectionscursor=connecti ...
- Jquery分享插件
效果图如下: 代码如下: <!DOCTYPE HTML> <html style="padding-bottom: 54px;"> <head> ...
- JS将图片转换成Base64码
直接上代码 html页面代码 <!DOCTYPE html> <html lang="en"> <head> <meta charset= ...
- Python装饰器执行顺序详解
探究多个装饰器执行顺序 装饰器是Python用于封装函数或代码的工具,网上可以搜到很多文章可以学习,我在这里要讨论的是多个装饰器执行顺序的一个迷思. 疑问 大部分涉及多个装饰器装饰的函数调用顺序时都会 ...
- 洛谷P4336 [SHOI2016]黑暗前的幻想乡 [Matrix-Tree定理,容斥]
传送门 思路 首先看到生成树计数,想到Matrix-Tree定理. 然而,这题显然是不能Matrix-Tree定理硬上的,因为还有每个公司只能建一条路的限制.这个限制比较恶心,尝试去除它. 怎么除掉它 ...
- oracle存储大文本clob、blob
oracle存储大文本clob.blob 1 package cn.itcast.web.oracle.util; 2 3 import java.sql.Connection; 4 import j ...
- 洛谷 P3627 [APIO2009]抢掠计划
这题一看就是缩点,但是缩完点怎么办呢?首先我们把所有的包含酒吧的缩点找出来,打上标记,然后建立一张新图, 每个缩点上的点权就是他所包含的所有点的点权和.但是建图的时候要注意,每一对缩点之间可能有多条边 ...
- FromData获取表单数据
一般想要不刷新页面提交数据时,可以使用ajax提交.如果数据量不大可以自己写json数据用ajax提交到后台服务,但是数据量多且需要动态添加数据时,自己写json格式数据就有点麻烦了,这时候就需要Fo ...