forked from ISTE-VIT/CodeZap-2020
-
Notifications
You must be signed in to change notification settings - Fork 0
/
drogos-dilemma.cpp
61 lines (57 loc) · 1.43 KB
/
drogos-dilemma.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
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
//code
int t; cin>>t;
while(t--){
int n,m; cin>>n>>m; int arr1[n+1],arr2[m+1];
for(int x=0; x<n; x++) cin>>arr1[x];
arr1[n]=0;
for(int y=0; y<m; y++) cin>>arr2[y];
arr2[m]=0;
int i=0,j=0,sum1=0,sum2=0,tsum=0,l1=0,l2=0;
while(i<n && j<m){
if(arr1[i]<arr2[j]){
sum1+=arr1[i];
i++;
}
else if(arr2[j]<arr1[i]){
sum2+=arr2[j];
j++;
}
else{
if(arr1[i]==arr1[i+1]){
sum1+=arr1[i];
i++;
}
else if(arr2[j]==arr2[j+1]){
sum2+=arr2[j];
j++;
}
else{
tsum=tsum+max(sum1,sum2)+arr1[i];
sum1=0; sum2=0;
i++; j++;
}
l1=i; l2=j;
}
//cout<<"tsum:"<<tsum<<endl;
}
sum1=0;sum2=0;
while(l1<n){
sum1+=arr1[l1];
l1++;
}
while(l2<m){
sum2+=arr2[l2];
l2++;
}
tsum+=max(sum1,sum2);
cout<<tsum<<endl;
}
return 0;
}