来源:LFYZOJ
1 #include<cstdio> 2 #include<iostream> 3 using namespace std; 4 int ans=0, a[100005], b[100005]; 5 int n, m, i, j; 6 int main(){ 7 cin>>n>>m; 8 for(i=0; i<n; i++) 9 cin>>a[i]; 10 for(j=0; j<m; j++) 11 cin>>b[j]; 12 int k=a[--i]; 13 int p=b[--j]; 14 cout<<k<<" "<<p<<endl; 15 while(i>-1 || j>-1){ 16 while(k>p) p+=b[--j]; 17 while(k<p) k+=a[--i]; 18 if(k==p) { 19 cout<<k<<endl; 20 ans++; 21 k=a[--i]; 22 p=b[--j]; 23 } 24 } 25 cout<<ans; 26 return 0; 27 }