-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathB.TernarySequence.cpp
45 lines (44 loc) · 945 Bytes
/
B.TernarySequence.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
#include <bits/stdc++.h>
#define ll long long int
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
freopen("input.txt","r",stdin);
freopen("Output.txt","w",stdout);
#endif
int t;
cin >> t;
for (int tt = 0; tt < t; tt++)
{
int x1, x2, y1, y2, z1, z2;
cin >> x1 >> y1 >> z1;
cin>> x2 >> y2 >> z2;
ll sum = 0;
int res = min(z1, y2);
sum = sum + 2 * res;
z1 = z1 - res;
y2 = y2 - res;
if (z1 > 0)
{
res = min(z1, z2);
z1 = z1 - res;
z2 = z2 - res;
}
if (z2 > 0)
{
res = min(z2, x1);
x1 = x1 - res;
z2 = z2 - res;
}
if (z2 > 0)
{
res = min(z2, y1);
sum = sum - 2 * res;
y1 = y1 - res;
z2 = z2 - res;
}
cout << sum << endl;
}
return 0;
}