A15336 | Madoka and Formal Statement
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
Given an array of integer $a_1, a_2, \ldots, a_n$ . In one operation you can make $a_i := a_i + 1$ if $i < n$ and $a_i \leq a_{i + 1}$ , or $i = n$ and $a_i \leq a_1$ .
You need to check whether the array $a_1, a_2, \ldots, a_n$ can become equal to the array $b_1, b_2, \ldots, b_n$ in some number of operations (possibly, zero). Two arrays $a$ and $b$ of length $n$ are called equal if $a_i = b_i$ for all integers $i$ from $1$ to $n$ .
You need to check whether the array $a_1, a_2, \ldots, a_n$ can become equal to the array $b_1, b_2, \ldots, b_n$ in some number of operations (possibly, zero). Two arrays $a$ and $b$ of length $n$ are called equal if $a_i = b_i$ for all integers $i$ from $1$ to $n$ .
输入格式
The input consists of multiple test cases. The first line contains a single integer $t$ ( $1 \le t \le 4 \cdot 10^4$ ) — the number of test cases. Description of the test cases follows.
The first line of each test case contains a single integer $n$ ( $2 \le n \le 2 \cdot 10^5$ ) – the length of the array.
The second line of each test case contains $n$ integers $a_1, \ldots, a_n$ ( $1 \le a_i \le 10^9$ ) – the elements of the array $a$ .
The third line of each test case contains $n$ integers $b_1, \ldots, b_n$ ( $1 \le b_i \le 10^9$ ) – the elements of the array $b$ .
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$ .
The first line of each test case contains a single integer $n$ ( $2 \le n \le 2 \cdot 10^5$ ) – the length of the array.
The second line of each test case contains $n$ integers $a_1, \ldots, a_n$ ( $1 \le a_i \le 10^9$ ) – the elements of the array $a$ .
The third line of each test case contains $n$ integers $b_1, \ldots, b_n$ ( $1 \le b_i \le 10^9$ ) – the elements of the array $b$ .
It is guaranteed that the sum of $n$ over all test cases does not exceed $2 \cdot 10^5$ .
输出格式
For each test case, output "YES" if you can get the array $b$ , otherwise output "NO".
You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as positive answer).
You may print each letter in any case (for example, "YES", "Yes", "yes", "yEs" will all be recognized as positive answer).
输入输出样例
输入 #1
5 3 1 2 5 1 2 5 2 2 2 1 3 4 3 4 1 2 6 4 2 5 3 2 4 1 4 5 3 5 1 2 3 4 5 6 5 6 7 6
输出 #1
YES NO NO NO YES
In the first test case, the array $a$ is already equal to the array $b$ .
In the second test case, we can't get the array $b$ , because to do this we need to decrease $a_1$ .
In the fifth test case, we can apply operations in order to the elements with indices $4, 3, 3,2,2,2,1,1,1,1$ , and then get the array $[5,5,5,5,5]$ . After that, you can apply operations in order to elements with indices $5,4,4,3,1$ and already get an array $[6,5,6,7,6]$ .
In the second test case, we can't get the array $b$ , because to do this we need to decrease $a_1$ .
In the fifth test case, we can apply operations in order to the elements with indices $4, 3, 3,2,2,2,1,1,1,1$ , and then get the array $[5,5,5,5,5]$ . After that, you can apply operations in order to elements with indices $5,4,4,3,1$ and already get an array $[6,5,6,7,6]$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted