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的更多相关文章

  1. Music in Car CodeForces - 746F

    Music in Car CodeForces - 746F 题意很难懂啊... 题意:http://blog.csdn.net/a838502647/article/details/74831793 ...

  2. Music in Car CodeForces - 746F (贪心,模拟)

    大意: n首歌, 第$i$首歌时间$t_i$, 播放完获得贡献$a_i$, 最多播放k分钟, 可以任选一首歌开始按顺序播放, 最多选w首歌半曲播放(花费时间上取整), 求贡献最大值. 挺简单的一个题, ...

  3. Codeforces Round #386 (Div. 2) 746F(set的运用)

    题目大意 给出一个歌单(有n首歌),每个歌都有愉悦值和时间,你可以选择从第x首歌开始听(也就是选择连续的一段),并且你可以选择w首歌让它的时间减半,限制时间为k,求最大的愉悦值 首先我们需要贪心一下, ...

  4. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  5. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  6. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  7. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  8. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  9. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

随机推荐

  1. webpack配置的基本介绍

    https://github.com/DDFE/DDFE-blog/issues/10 全局安装 webpack :(当前笔记版本: webpack  3.10.0 , mac环境) 1. npm i ...

  2. jqueryui组件progressbar进度条和日期组件datepickers的简单使用

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. 【原创】大叔问题定位分享(32)mysql故障恢复

    mysql启动失败,一直crash,报错如下: 2019-03-14T11:15:12.937923Z 0 [Note] InnoDB: Uncompressed page, stored check ...

  4. Java实现三大简单排序算法

    一.选择排序 public static void main(String[] args) { int[] nums = {1,2,8,4,6,7,3,6,4,9}; for (int i=0; i& ...

  5. Spring动态数据源实现读写分离

    一.创建基于ThreadLocal的动态数据源容器,保证数据源的线程安全性 package com.bounter.mybatis.extension; /** * 基于ThreadLocal实现的动 ...

  6. 排查linux系统是否被入侵

    在日常繁琐的运维工作中,对linux服务器进行安全检查是一个非常重要的环节.今天,分享一下如何检查linux系统是否遭受了入侵? 一.是否入侵检查 1)检查系统日志 检查系统错误登陆日志,统计IP重试 ...

  7. 牛客网 python 求解立方根

    •计算一个数字的立方根,不使用库函数 详细描述: •接口说明 原型: public static double getCubeRoot(double input) 输入:double 待求解参数 返回 ...

  8. boolalpha的作用

    #include <iostream>using namespace std;int main(){        bool b=true;        cout << &q ...

  9. FTP服务器配置和管理

    一:ftp 简介 1:ftp服务: internet 是一个非常复杂额计算机环境,其中有pc/mac/小型机/大型机等.而在这些计算机上运行的操作系统也是五花八门,有 unix.Linux.微软的wi ...

  10. deepin、Ubuntu安装Nginx

    deepin安装nginx 切换至root用户 su 密码: 基础库的安装 安装gcc g++的依赖库 sudo apt-get install build-essential && ...