Advertisement
Centipede18

A. T4k3D4Ch14

Apr 6th, 2018
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.56 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main() {
  6.     ios_base::sync_with_stdio(0);
  7.     cin.tie(NULL); cout.tie(NULL);
  8.  
  9.     int n, m, ans = 0; cin >> n >> m;
  10.     vector<int> a(n), b(m);
  11.     for (int i=0; i<n; i++) cin >> a[i];
  12.     for (int i=0; i<m; i++) cin >> b[i];
  13.  
  14.     int ptr1 = 0, ptr2 = 0, s1 = a[0], s2 = b[0];
  15.     while (ptr1 < n && ptr2 < m) {
  16.         if (s1 == s2) {
  17.             ptr1++; ptr2++; ans++;
  18.             s1 += a[ptr1]; s2 += b[ptr2];
  19.         }
  20.         else if (s1 < s2) {ptr1++; s1 += a[ptr1];}
  21.         else {ptr2++; s2 += b[ptr2];}
  22.     }
  23.  
  24.     cout << ans;
  25.     return 0;
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement