Codeforces Round 1012 (Div. 1)
B1
Canteen (Easy Version)
Codeforces
1900
原题
← AB2 →
翻译中…

This is the easy version of the problem. The difference between the versions is that in this version, $k=0$. You can hack only if you solved all versions of this problem.

翻译中…

Ecrade has two sequences $a_0, a_1, \ldots, a_{n - 1}$ and $b_0, b_1, \ldots, b_{n - 1}$ consisting of integers. It is guaranteed that the sum of all elements in $a$ does not exceed the sum of all elements in $b$.

翻译中…

Initially, Ecrade can make exactly $k$ changes to the sequence $a$. It is guaranteed that $k$ does not exceed the sum of $a$. In each change:

翻译中…
  • Choose an integer $i$ ($0 \le i \lt n$) such that $a_i \gt 0$, and perform $a_i := a_i - 1$.
翻译中…

Then Ecrade will perform the following three operations sequentially on $a$ and $b$, which constitutes one round of operations:

翻译中…
  1. For each $0 \le i \lt n$: $t := \min(a_i, b_i), a_i := a_i - t, b_i := b_i - t$;
  2. For each $0 \le i \lt n$: $c_i := a_{(i - 1) \bmod n}$;
  3. For each $0 \le i \lt n$: $a_i := c_i$;
翻译中…

Ecrade wants to know the minimum number of rounds required for all elements in $a$ to become equal to $0$ after exactly $k$ changes to $a$.

翻译中…

However, this seems a bit complicated, so please help him!

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 2\cdot 10^4$). The description of the test cases follows.

翻译中…

The first line of each test case contains two integers $n$, $k$ ($1 \le n \le 2 \cdot 10^5$, $k = 0$).

翻译中…

The second line of each test case contains $n$ integers $a_0, a_1, \ldots, a_{n - 1}$ ($1 \le a_i \le 10^9$).

翻译中…

The third line of each test case contains $n$ integers $b_0, b_1, \ldots, b_{n - 1}$ ($1 \le b_i \le 10^9$).

翻译中…

It is guaranteed that the sum of $n$ across all test cases does not exceed $2\cdot 10^5$. It is also guaranteed that in each test case the sum of $a$ does not exceed the sum of $b$, and that $k$ does not exceed the sum of $a$.

翻译中…

Output

翻译中…

For each test case, output the minimum number of rounds required for all elements in $a$ to become equal to $0$ after exactly $k$ changes to $a$.

翻译中…

Note

翻译中…

In this version, Ecrade cannot make changes to $a$.

翻译中…

In the first test case:

翻译中…
  • After the first round, $a=[0,0,0],b=[4,0,0]$.
翻译中…

In the second test case:

翻译中…
  • After the first round, $a=[3,0,0,1],b=[3,1,0,0]$;
  • After the second round, $a=[1,0,0,0],b=[0,1,0,0]$;
  • After the third round, $a=[0,1,0,0],b=[0,1,0,0]$;
  • After the fourth round, $a=[0,0,0,0],b=[0,0,0,0]$.
翻译中…

样例

Input #1
4
3 0
1 1 4
5 1 4
4 0
1 2 3 4
4 3 2 1
4 0
2 1 1 2
1 2 2 1
8 0
1 2 3 4 5 6 7 8
8 7 6 5 4 3 2 1
Output #1
1
4
4
8
InputCopy OutputCopy
题目信息
题号
2089B1
时间限制
2 s
内存限制
512 MB
标签
二分
数据结构
网络流
贪心
双指针

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。