#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll pre_sum1[100010],pre_sum2[100010];
int l1=1,r1=1,l2=1,r2=1;
int main(){
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++){
int t;
cin>>t;
pre_sum1[i]=pre_sum1[i-1]+t;
}
for(int i=1;i<=m;i++){
int t;
cin>>t;
pre_sum2[i]=pre_sum2[i-1]+t;
}
int res=0;
for(;r1<=n&&r2<=m;){
while(r1<=n&&r2<=m&&pre_sum1[r1]-pre_sum1[l1-1]!=pre_sum2[r2]-pre_sum2[l2-1]){
if(pre_sum1[r1]-pre_sum1[l1-1]>pre_sum2[r2]-pre_sum2[l2-1]){
r2++;
}
else{
r1++;
}
}
res++;
r1++;
l1=r1;
r2++;
l2=r2;
}
cout<<res;
return 0;
}
AcWing 4380. 合并石子(贪心+前缀和+双指针)
最新推荐文章于 2024-08-21 18:53:45 发布