#include<iostream> #include <stdio.h> #include <string.h> #define LL long long using namespace std; const int maxn = 1e6; LL qzh[maxn]; LL QZH[maxn]; int main() { int n, m; cin >> n >> m; int a[100005]; int b[100005]; qzh[0] = 0; QZH[0] = 0; int x, y; //Qzh[0] = 0; int sum = 0; for (int i = 1; i <= n; ++i) { cin >> x; qzh[i] = qzh[i - 1] + x; } int tt = 1; for (int j = 1; j <= m; ++j) { cin >> y; QZH[j] = QZH[j - 1] + y; } if (n == 1 || m == 1) { cout << 1 << endl; return 0; } int ans = 0; if (n == m) { int t1 = 1, t2 = 1; for (int i = 1; t1 <= n && t2 <= m; i++) { if (qzh[t1] == QZH[t2]) { ans++; t1++; t2++; } else if (qzh[t1] < QZH[t2]) { t1++; } else if (qzh[t1] > QZH[t2]) { t2++; } } cout << ans << endl; } if (n > m||n<m) { int t1 = 1, t2 = 1; for (int i = 1; t1<=n&&t2<=m; i++) { if (qzh[t1] == QZH[t2]) { ans++; t1++; t2++; } else if (qzh[t1] < QZH[t2]) { t1++; } else if (qzh[t1] > QZH[t2]) { t2++; } } cout << ans << endl; } return 0; }
Codeforces Round #469 (Div. 2)
猜你喜欢
转载自blog.csdn.net/qq_36294146/article/details/79504184
今日推荐
周排行