CF1873F.Money Trees
普及-
通过率:0%
时间限制:2.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Luca is in front of a row of n trees. The i-th tree has ai fruit and height hi.
He wants to choose a contiguous subarray of the array [hl,hl+1,…,hr] such that for each i (l≤i<r), hi is divisible† by hi+1. He will collect all the fruit from each of the trees in the subarray (that is, he will collect al+al+1+⋯+ar fruits). However, if he collects more than k fruits in total, he will get caught.
What is the maximum length of a subarray Luca can choose so he doesn't get caught?
† x is divisible by y if the ratio yx is an integer.
卢卡站在一排 n 棵树前。第 i 棵树上有 ai 个果实,高度为 hi。
他希望选择数组 [hl,hl+1,…,hr] 的一个连续子数组,使得对每个 i(满足 l≤i<r),hi 都能被 hi+1 整除†。他将收集该子数组中每棵树上的所有果实(即共收集 al+al+1+⋯+ar 个果实)。然而,若他收集的果实总数超过 k 个,他就会被抓住。
卢卡在不被抓住的前提下,所能选择的子数组的最大长度是多少?
† 若比值 yx 是整数,则称 x 能被 y 整除。
输入格式
The first line contains a single integer t (1≤t≤1000) — the number of test cases.
The first of each test case line contains two space-separated integers n and k (1≤n≤2⋅105; 1≤k≤109) — the number of trees and the maximum amount of fruits Luca can collect without getting caught.
The second line of each test case contains n space-separated integers ai (1≤ai≤104) — the number of fruits in the i-th tree.
The third line of each test case contains n space-separated integers hi (1≤hi≤109) — the height of the i-th tree.
The sum of n over all test cases does not exceed 2⋅105.
第一行包含一个整数 t(1≤t≤1000),表示测试用例的数量。
每个测试用例的第一行包含两个以空格分隔的整数 n 和 k(1≤n≤2⋅105;1≤k≤109),分别表示树的数量以及Luca在不被发现的前提下最多能采集的水果总数。
每个测试用例的第二行包含 n 个以空格分隔的整数 ai(1≤ai≤104),表示第 i 棵树上的水果数量。
每个测试用例的第三行包含 n 个以空格分隔的整数 hi(1≤hi≤109),表示第 i 棵树的高度。
所有测试用例中 n 的总和不超过 2⋅105。
输出格式
For each test case output a single integer, the length of the maximum length contiguous subarray satisfying the conditions, or 0 if there is no such subarray.
对于每个测试用例,输出一个整数:满足条件的最长连续子数组的长度;若不存在这样的子数组,则输出 0。
输入输出样例
输入#1
5 5 12 3 2 4 1 8 4 4 2 4 1 4 8 5 4 1 2 6 2 3 1 3 12 7 9 10 2 2 4 1 10 11 1 7 10 2 6 3 1 5 10 6 72 24 24 12 4 4 2
输出#1
3 2 1 0 3
说明/提示
In the first test case, Luca can select the subarray with l=1 and r=3.
In the second test case, Luca can select the subarray with l=3 and r=4.
In the third test case, Luca can select the subarray with l=2 and r=2.
在第一个测试用例中,Luca 可以选择满足 l=1 和 r=3 的子数组。
在第二个测试用例中,Luca 可以选择满足 l=3 和 r=4 的子数组。
在第三个测试用例中,Luca 可以选择满足 l=2 和 r=2 的子数组。
输入解题思路,AI测评打分。不知道怎么写?