CF671E.Organizing a Race

NOI/NOI+/CTSC

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

Kekoland is a country with n beautiful cities numbered from left to right and connected by n - 1 roads. The i-th road connects cities i and i + 1 and length of this road is w__i kilometers.

When you drive in Kekoland, each time you arrive in city i by car you immediately receive g__i liters of gas. There is no other way to get gas in Kekoland.

You were hired by the Kekoland president Keko to organize the most beautiful race Kekoland has ever seen. Let race be between cities l and r (l ≤ r). Race will consist of two stages. On the first stage cars will go from city l to city r. After completing first stage, next day second stage will be held, now racers will go from r to l with their cars. Of course, as it is a race, racers drive directly from start city to finish city. It means that at the first stage they will go only right, and at the second stage they go only left. Beauty of the race between l and r is equal to r - l + 1 since racers will see r - l + 1 beautiful cities of Kekoland. Cars have infinite tank so racers will take all the gas given to them.

At the beginning of each stage racers start the race with empty tank (0 liters of gasoline). They will immediately take their gasoline in start cities (l for the first stage and r for the second stage) right after the race starts.

It may not be possible to organize a race between l and r if cars will run out of gas before they reach finish.

You have k presents. Each time you give a present to city i its value g__i increases by 1. You may distribute presents among cities in any way (also give many presents to one city, each time increasing g__i by 1). What is the most beautiful race you can organize?

Each car consumes 1 liter of gas per one kilometer.

Kekoland 是一个拥有 nn 座美丽城市的国家,这些城市从左到右依次编号,并由 n−1n-1 条道路连接。第 ii 条道路连接城市 ii 和 i+1i+1,其长度为 wiw_i 千米。

在 Kekoland 驾车行驶时,每次你驾车抵达城市 ii,便会立即获得 gig_i 升汽油。在 Kekoland 中,这是获取汽油的唯一方式。

你受 Kekoland 总统 Keko 的委托,组织一场 Kekoland 有史以来最盛大的赛车比赛。设比赛在城市 ll 与 rr 之间举行(其中 l≤rl \le r)。比赛分为两个阶段:第一阶段,赛车从城市 ll 驾驶至城市 rr;完成第一阶段后,次日举行第二阶段,赛车从城市 rr 驾驶返回至城市 ll。当然,既然是比赛,赛车手将直接从起点城市驶向终点城市。这意味着:在第一阶段中,他们仅能向右行驶;而在第二阶段中,则仅能向左行驶。城市 ll 与 rr 之间比赛的“美丽度”定义为 r−l+1r - l + 1,因为赛车手将途经 Kekoland 的 r−l+1r - l + 1 座美丽城市。汽车油箱容量无限,因此赛车手将领取并使用所有可获得的汽油。

在每个阶段开始时,赛车手均以空油箱(即 0 升汽油)出发。比赛一开始,他们便立即在起点城市(第一阶段为城市 ll,第二阶段为城市 rr)领取该城市的汽油。

若赛车手在抵达终点前耗尽汽油,则无法在城市 ll 与 rr 之间成功组织比赛。

你拥有 kk 份礼物。每向城市 ii 赠送一份礼物,其汽油量 gig_i 就增加 1。你可以任意分配这些礼物(包括将多份礼物全部赠予同一座城市,每次使 gig_i 增加 1)。请问:你能组织的最美丽(即 r−l+1r-l+1 最大)的比赛是什么?

每辆汽车每行驶 1 千米消耗 1 升汽油。

输入格式

The first line of the input contains two integers n and k (2 ≤ n ≤ 100 000, 0 ≤ k ≤ 109) — the number of cities in Kekoland and the number of presents you have, respectively.

Next line contains n - 1 integers. The i-th of them is w__i (1 ≤ w__i ≤ 109) — the length of the road between city i and i + 1.

Next line contains n integers. The i-th of them is g__i (0 ≤ g__i ≤ 109) — the amount of gas you receive every time you enter city i.

输入的第一行包含两个整数 nn 和 kk(2≤n≤100 0002 \leq n \leq 100\,000,0≤k≤1090 \leq k \leq 10^9)——分别表示 Kekoland 中的城市数量以及你所拥有的礼物数量。

下一行包含 n−1n-1 个整数。其中第 ii 个整数为 wiw_i(1≤wi≤1091 \leq w_i \leq 10^9)——表示城市 ii 与城市 i+1i+1 之间道路的长度。

再下一行包含 nn 个整数。其中第 ii 个整数为 gig_i(0≤gi≤1090 \leq g_i \leq 10^9)——表示每次进入城市 ii 时你所获得的汽油量。

输出格式

Print a single line — the beauty of the most beautiful race you can organize.

输出一行——你能组织的最美丽比赛的美丽值。

输入输出样例

  • 输入#1

    4 4
    2 2 2
    1 1 1 1

    输出#1

    4
  • 输入#2

    8 5
    2 2 2 3 7 3 1
    1 3 1 5 4 0 2 5

    输出#2

    7

说明/提示

In first sample if you give one present to each city then it will be possible to make a race between city 1 and city 4.

In second sample you should add 1 to _g_5 and 4 to _g_6, then it will be possible to make a race between cities 2 and 8.

在第一个样例中,如果给每个城市各赠送一个礼物,那么就可以在城市 1 和城市 4 之间举办一场比赛。

在第二个样例中,你应该将 1 加到 g5g_5 上、将 4 加到 g6g_6 上,之后就可以在城市 2 和城市 8 之间举办一场比赛。

输入解题思路,AI测评打分。不知道怎么写?

首页