A10435 | Organizing a Race
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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.
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.
输入格式
The first line of the input contains two integers $n$ and $k$ ( $2<=n<=100000$ , $0<=k<=10^{9}$ ) — 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}<=10^{9}$ ) — 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}<=10^{9}$ ) — the amount of gas you receive every time you enter city $i$ .
Next line contains $n-1$ integers. The $i$ -th of them is $w_{i}$ ( $1<=w_{i}<=10^{9}$ ) — 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}<=10^{9}$ ) — the amount of gas you receive every time you enter city $i$ .
输出格式
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$ .
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$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted