forked from arv002-zz/spojcodes
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ANARC05B - The Double HeLiX.cpp
68 lines (58 loc) · 1.23 KB
/
ANARC05B - The Double HeLiX.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
66
67
68
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long n,m;
while(1>0)
{
cin>>n;
if(n==0)
break;
long long i,j,k,sum1=0,sum2=0,sum=0;
long long a[n];
for(i=0; i<n; i++)
cin>>a[i];
cin>>m;
long long b[m];
for(j=0; j<m; j++)
cin>>b[j];
i=0;
j=0;
while(i<n || j<m)
{
if(a[i]==b[j])
{
sum1+=a[i];
sum2+=b[j];
sum+=max(sum1,sum2);
//cout<<max(sum1,sum2)<<" ";
sum1=0;
sum2=0;
i++;
j++;
}
else if(a[i]>b[j])
{
sum2+=b[j];
j++;
}
else if(a[i]<b[j])
{
sum1+=a[i];
i++;
}
}
if(i<n)
{
for(k=i; k<n; k++)
sum1+=a[k];
}
if(j<m)
{
for(k=j; k<m; k++)
sum2+=b[k];
}
sum+=max(sum1,sum2);
cout<<sum<<"\n";
}
}