Money Trees
用双指针不断的收缩区间即可
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+10;
int a[N],b[N];
void solve(){
int n,k;
cin>>n>>k;
for(int i=1;i<=n;i++)cin>>a[i];
for(int i=1;i<=n;i++)cin>>b[i];
int ans=0,sum=0;
int j=1;
for(int i=1;i<=n-1;i++){
sum+=a[i];
while(sum>k&&j<=i){
sum-=a[j];
j++;
}
ans=max(ans,i-j+1);
if(b[i]%b[i+1]!=0){
sum=0;
j=i+1;
}
}
sum+=a[n];
while(sum>k&&j<=n){
sum-=a[j];
j++;
}
ans=max(ans,n-j+1);
cout<<ans<<"\n";
}
int main(){
ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int t=1;
cin>>t;
for(int i=1;i<=t;i++)solve();
return 0;
}
标签:14,int,Money,Trees,ik,&&
From: https://www.cnblogs.com/yufan1102/p/17973545