Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- using namespace std;
- int main() {
- ios_base::sync_with_stdio(0);
- cin.tie(NULL); cout.tie(NULL);
- int n, m, ans = 0; cin >> n >> m;
- vector<int> a(n), b(m);
- for (int i=0; i<n; i++) cin >> a[i];
- for (int i=0; i<m; i++) cin >> b[i];
- int ptr1 = 0, ptr2 = 0, s1 = a[0], s2 = b[0];
- while (ptr1 < n && ptr2 < m) {
- if (s1 == s2) {
- ptr1++; ptr2++; ans++;
- s1 += a[ptr1]; s2 += b[ptr2];
- }
- else if (s1 < s2) {ptr1++; s1 += a[ptr1];}
- else {ptr2++; s2 += b[ptr2];}
- }
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement