forked from debsourav33/CodeForces-Problem-Solutions
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1036D-Vasya and Arrays .cpp
65 lines (52 loc) · 1.12 KB
/
1036D-Vasya and Arrays .cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include<bits/stdc++.h>
using namespace std;
//{
#define cel(n,k) ((n-1)/k+1)
#define sets(a) memset(a, -1, sizeof(a))
#define clr(a) memset(a, 0, sizeof(a))
#define max(a,b) ((a)>(b)? (a):(b))
#define min(a,b) ((a)<(b)? (a):(b))
#define fr(n) for(int i=0;i<n;i++)
#define fr1(n) for(int i=1;i<=n;i++)
#define pb push_back
#define all(v) v.begin(),v.end()
#define mp make_pair
#define ff first
#define ss second
#define INF 1000000010
typedef long l;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
//}
int m, n, a[300005], b[300005], cnt=0, i=0, j=0;
ull s1, s2;
main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cin>>m;
fr(m)
cin>>a[i];
cin>>n;
fr(n)
cin>>b[i];
s1= a[0]; s2= b[0];
while(i<m && j<n){
if(s1==s2){
++cnt;
s1= a[++i];
s2= b[++j];
continue;
}
if(s1<s2)
s1+= a[++i];
else
s2+= b[++j];
}
if(i!=m || j!=n){
cout<<"-1"<<endl;
return 0;
}
cout<<cnt<<endl;
}