您的位置:首页 > 其它

CodeForces - 746F : Music in Car(set)

2017-07-08 15:15 260 查看
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.

Input

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 the i-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.

Output

Print the maximum pleasure Sasha can get after listening to the songs on the way to work.

Input

7 2 11

3 4 3 5 1 4 6

7 7 3 6 5 3 9

Output

12

Input

8 4 20

5 6 4 3 7 5 4 1

10 12 5 12 14 8 5 8

Output

19

Input

1 1 5

6

9

Output

6

Input

1 1 3

4

7

Output

0

题意 :有N个数组成的序列,第i个数消费 ti ,获得满意度 pi, 选择其中一段花费不超过k的连续的序列,使获得的满意度最大 ,其中最多可以使 任意w个花费减半(向上取整).

思路:维护两个set,一个记录当前“打折”过的花费,一个记录没有打折过的花费,从左往右遍历,记录当前遍历区间L,R值,当insert (R+1)时,先把它加入打折队列,当打折队列的元素>w时弹出最小元素到没有打折过的队列。  erase(l-1)时 判断是否比打折队列末尾值小,小于末尾的话直接删除非打折队列里的值就行,大于的话删除对应值,并从非打折队列末尾添加一个元素到打折队列中.

#include <iostream>
using namespace std;
#include <algorithm>
#include <set>
#include <stdio.h>
#define MAX 200005
#define ll long

ll max(ll a,ll b)
{
return a>b?a:b;
}

multiset<int> wa;
multiset<int> tle;
multiset<int>::iterator it;

int main()
{
int t[MAX],p[MAX];
int i,k,n,w;
scanf("%d %d %d",&n,&w,&k);
for(i=0;i<n;i++)
scanf("%d",&p[i]);
for(i=0;i<n;i++)
scanf("%d",&t[i]);
int ctime=0,cnum=0,l=0,r=0,csum=0,ans=0;
while(r<n)
{
wa.insert(t[r]);
ctime+=(t[r]+1)/2;
if(wa.size()>w)
{
tle.insert(*(wa.begin()));
ctime+=*( wa.begin() ) /2;
wa.erase(wa.begin());
}
csum+=p[r++];
while(l<=r && ctime>k)
{
if(t[l]>=* ( wa.begin() ) )
{
wa.erase( wa.find( t[l] ) );
ctime-=(t[l]+1)/2;
if(tle.size())
{
it = tle.end();
it--;
wa.insert( *it );
ctime-= *it/2;
tle.erase( it );
}
}
else
{
tle.erase( tle.find( t[l] ) );
ctime-=t[l];
}
csum-=p[l++];
}
ans=max(ans,csum);
}
printf("%d\n",ans);
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  acm codeforces