Music in Car
1 second
256 megabytes
Sasha reaches the work by car. It takes exactly k minutes. On his way he listens to music. All songs in his playlist go one by one, after listening to the i-th song Sasha gets a pleasure which equals ai. The i-th song lasts for ti minutes.
Before the beginning of his way Sasha turns on some song x and then he listens to the songs one by one: at first, the song x, then the song (x + 1), then the song number (x + 2), and so on. He listens to songs until he reaches the work or until he listens to the last song in his playlist.
Sasha can listen to each song to the end or partly.
In the second case he listens to the song for integer number of minutes, at least half of the song's length. Formally, if the length of the song equals d minutes, Sasha listens to it for no less than minutes, then he immediately switches it to the next song (if there is such). For example, if the length of the song which Sasha wants to partly listen to, equals 5 minutes, then he should listen to it for at least 3 minutes, if the length of the song equals 8 minutes, then he should listen to it for at least 4 minutes.
It takes no time to switch a song.
Sasha wants to listen partly no more than w songs. If the last listened song plays for less than half of its length, then Sasha doesn't get pleasure from it and that song is not included to the list of partly listened songs. It is not allowed to skip songs. A pleasure from a song does not depend on the listening mode, for the i-th song this value equals ai.
Help Sasha to choose such x and no more than w songs for partial listening to get the maximum pleasure. Write a program to find the maximum pleasure Sasha can get from the listening to the songs on his way to the work.
The first line contains three integers n, w and k (1 ≤ w ≤ n ≤ 2·105, 1 ≤ k ≤ 2·109) — the number of songs in the playlist, the number of songs Sasha can listen to partly and time in minutes which Sasha needs to reach work.
The second line contains n positive integers a1, a2, ..., an (1 ≤ ai ≤ 104), where ai equals the pleasure Sasha gets after listening to thei-th song.
The third line contains n positive integers t1, t2, ..., tn (2 ≤ ti ≤ 104), where ti equals the length of the i-th song in minutes.
Print the maximum pleasure Sasha can get after listening to the songs on the way to work.
7 2 11
3 4 3 5 1 4 6
7 7 3 6 5 3 9
12
8 4 20
5 6 4 3 7 5 4 1
10 12 5 12 14 8 5 8
19
1 1 5
6
9
6
1 1 3
4
7
0
In the first example Sasha needs to start listening from the song number 2. He should listen to it partly (for 4 minutes), then listen to the song number 3 to the end (for 3 minutes) and then partly listen to the song number 4 (for 3 minutes). After listening to these songs Sasha will get pleasure which equals 4 + 3 + 5 = 12. Sasha will not have time to listen to the song number 5 because he will spend4 + 3 + 3 = 10 minutes listening to songs number 2, 3 and 4 and only 1 minute is left after that.
分析:two pointer+ two sets;
一个set维护听part的歌曲,一个维护full;
右指针向右时,优先考虑能否part,若不能,考虑full或将part里替换出一个来;
左指针向右delete后,考虑能否将full的加到part里;
代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <bitset>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, ls[rt]
#define Rson mid+1, R, rs[rt]
#define sys system("pause")
const int maxn=2e5+;
using namespace std;
ll gcd(ll p,ll q){return q==?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=;while(q){if(q&)f=f*p%mod;p=p*p%mod;q>>=;}return f;}
inline void umax(int &p,int q){if(p<q)p=q;}
inline void umin(int &p,int q){if(p>q)p=q;}
inline ll read()
{
ll x=;int f=;char ch=getchar();
while(ch<''||ch>''){if(ch=='-')f=-;ch=getchar();}
while(ch>=''&&ch<=''){x=x*+ch-'';ch=getchar();}
return x*f;
}
int n,m,k,w,a[maxn],t[maxn],ma,now;
set<pii>full,half;
int main()
{
int i,j;
scanf("%d%d%d",&n,&k,&w);
rep(i,,n)a[i]=read();
rep(i,,n)t[i]=read();
int l,r;
l=r=;
while(r<=n)
{
//right pointer;
while(r<=n)
{
if(k)
{
if(w>=(t[r]+)/)
{
w-=(t[r]+)/;
umax(ma,now+=a[r]);
half.insert(mp(t[r],r));
r++;
k--;
}
else break;
}
else
{
int tmp=half.begin()->fi;
if(tmp<=t[r]&&w>=(t[r]+)/-(tmp+)/+tmp)
{
w-=(t[r]+)/-(tmp+)/+tmp;
umax(ma,now+=a[r]);
auto p=half.begin();
full.insert(*p);
half.erase(p);
half.insert(mp(t[r],r));
r++;
}
else if(tmp>t[r]&&w>=t[r])
{
w-=t[r];
umax(ma,now+=a[r]);
full.insert(mp(t[r],r));
r++;
}
else break;
}
}
//left pointer;
if(l<r)
{
if(full.find(mp(t[l],l))!=full.end())
{
w+=t[l];
now-=a[l];
full.erase(mp(t[l],l));
}
else
{
w+=(t[l]+)/;
now-=a[l];
half.erase(mp(t[l],l));
k++;
if(!full.empty())
{
auto p=--full.end();
w+=p->fi-(p->fi+)/;
half.insert(*p);
k--;
full.erase(p);
}
}
l++;
}
else l++,r++;
}
printf("%d\n",ma);
return ;
}
随机推荐
- IOS 京东相关app 出现“网络请求失败,请检查您的网络设置”的解决办法
问题情况 在IOS系统下,下载安装或者更新新版的京东相关app之后,打开app直接就是“网络请求失败,请检查网络设置”,无论是数据连接还是wifi都试了,都是网络请求失败. 然而打开无线局域网-使用无 ...
- Codeforces--630H--Benches(组合数)
H - Benches Crawling in process... Crawling failed Time Limit:500MS Memory Limit:65536KB 64b ...
- P1850 换教室 概率dp
其实说是概率dp,本质上和dp没什么区别,就是把所有可能转移的情况全枚举一下就行了,不过dp方程确实有点长... ps:这个题的floyed我竟然之前写跪了... 题目: 题目描述 对于刚上大学的牛牛 ...
- Android对话框与Activity共存时的异常
异常提示信息 01-01 18:30:38.630: E/WindowManager(14537): Activity com.jack.outstock.activity.ManageCustomA ...
- DCOM 找不到 office word 的解决方法
1. 在运行里面 输入 comexp.msc -32 2.在“DCOM配置”中,为IIS账号配置操作Word(其他Office对象也一样)的权限. 具体操作:“组件服务(Component ...
- TCP/IP详解(三)
超时与重传: TCP在发送一个包时,启动一个定时器,如果在定时器溢出之前没有收到ACK,则认为发出的包丢失了,此时会重传丢失的包.这就是超时重传. 其中定时器的时间不是一个固定值,它是根据RTT计算的 ...
- 去除DialogFragment的背景阴影,背景色,标题栏
style中: <resources xmlns:android="http://schemas.android.com/apk/res/android"> <s ...
- 【Oracle】OGG(Oracle GoldenGate)简介及搭建过程
GoldenGate公司简介 GoldenGate公司专注于数据同步领域,是实现数据同步技术的领导者.至2007年,在全球35个国家售出超过2000个许可证,客户分布在政府.银行.电信.证券.传媒.医 ...
- LinkedList 源码
1.类继承结构 结构: 2.成员及方法 注意:其中 getFirst,getLast,removeFirst,removeLast,el ...
- oracle从入门到精通复习笔记续集之PL/SQL(轻量版)
复习内容: PL/SQL的基本语法.记录类型.流程控制.游标的使用. 异常处理机制.存储函数/存储过程.触发器. 为方便大家跟着我的笔记练习,为此提供数据库表文件给大家下载:点我下载 为了要有输出的结 ...