A13656 | Network Coverage
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
The government of Berland decided to improve network coverage in his country. Berland has a unique structure: the capital in the center and $n$ cities in a circle around the capital. The capital already has a good network coverage (so the government ignores it), but the $i$ -th city contains $a_i$ households that require a connection.
The government designed a plan to build $n$ network stations between all pairs of neighboring cities which will maintain connections only for these cities. In other words, the $i$ -th network station will provide service only for the $i$ -th and the $(i + 1)$ -th city (the $n$ -th station is connected to the $n$ -th and the $1$ -st city).
All network stations have capacities: the $i$ -th station can provide the connection to at most $b_i$ households.
Now the government asks you to check can the designed stations meet the needs of all cities or not — that is, is it possible to assign each household a network station so that each network station $i$ provides the connection to at most $b_i$ households.
The government designed a plan to build $n$ network stations between all pairs of neighboring cities which will maintain connections only for these cities. In other words, the $i$ -th network station will provide service only for the $i$ -th and the $(i + 1)$ -th city (the $n$ -th station is connected to the $n$ -th and the $1$ -st city).
All network stations have capacities: the $i$ -th station can provide the connection to at most $b_i$ households.
Now the government asks you to check can the designed stations meet the needs of all cities or not — that is, is it possible to assign each household a network station so that each network station $i$ provides the connection to at most $b_i$ households.
输入格式
The first line contains a single integer $t$ ( $1 \le t \le 10^4$ ) — the number of test cases.
The first line of each test case contains the single integer $n$ ( $2 \le n \le 10^6$ ) — the number of cities and stations.
The second line of each test case contains $n$ integers ( $1 \le a_i \le 10^9$ ) — the number of households in the $i$ -th city.
The third line of each test case contains $n$ integers ( $1 \le b_i \le 10^9$ ) — the capacities of the designed stations.
It's guaranteed that the sum of $n$ over test cases doesn't exceed $10^6$ .
The first line of each test case contains the single integer $n$ ( $2 \le n \le 10^6$ ) — the number of cities and stations.
The second line of each test case contains $n$ integers ( $1 \le a_i \le 10^9$ ) — the number of households in the $i$ -th city.
The third line of each test case contains $n$ integers ( $1 \le b_i \le 10^9$ ) — the capacities of the designed stations.
It's guaranteed that the sum of $n$ over test cases doesn't exceed $10^6$ .
输出格式
For each test case, print YES, if the designed stations can meet the needs of all cities, or NO otherwise (case insensitive).
输入输出样例
输入 #1
5 3 2 3 4 3 3 3 3 3 3 3 2 3 4 4 2 3 4 5 3 7 2 2 4 4 5 2 3 2 3 2 7 2 1 1 10 10
输出 #1
YES YES NO YES YES
In the first test case:
- the first network station can provide $2$ connections to the first city and $1$ connection to the second city;
- the second station can provide $2$ connections to the second city and $1$ connection to the third city;
- the third station can provide $3$ connections to the third city.
In the second test case:
- the $1$ -st station can provide $2$ connections to the $1$ -st city;
- the $2$ -nd station can provide $3$ connections to the $2$ -nd city;
- the $3$ -rd station can provide $3$ connections to the $3$ -rd city and $1$ connection to the $1$ -st station.
In the third test case, the fourth city needs $5$ connections, but the third and the fourth station has $4$ connections in total.
- the first network station can provide $2$ connections to the first city and $1$ connection to the second city;
- the second station can provide $2$ connections to the second city and $1$ connection to the third city;
- the third station can provide $3$ connections to the third city.
In the second test case:
- the $1$ -st station can provide $2$ connections to the $1$ -st city;
- the $2$ -nd station can provide $3$ connections to the $2$ -nd city;
- the $3$ -rd station can provide $3$ connections to the $3$ -rd city and $1$ connection to the $1$ -st station.
In the third test case, the fourth city needs $5$ connections, but the third and the fourth station has $4$ connections in total.
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted