-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1945A.cpp
More file actions
55 lines (50 loc) · 1.43 KB
/
Copy path1945A.cpp
File metadata and controls
55 lines (50 loc) · 1.43 KB
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
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define f(i, x, n) for(int i = x; i < n; i++)
#define endl '\n'
#define optimize() ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int main() {
optimize();
ll t;
cin >> t;
while (t--) {
ll in, ex, un;
cin >> in >> ex >> un;
if (ex == 0 && un == 0) {
cout << in << endl;
} else if (ex > 0 && un == 0) {
if (ex % 3 == 0) {
cout << in + ex/3 << endl;
} else {
cout << -1 << endl;
}
} else if (ex == 0 && un > 0) {
if (un % 3 == 0) {
cout << in + un/3 << endl;
} else {
cout << in + un/3 + 1 << endl;
}
} else {
if (ex % 3 == 0) {
if (un % 3 == 0) {
cout << in + ex/3 + un/3 << endl;
} else {
cout << in + ex/3 + un/3 + 1 << endl;
}
} else {
ll num = (ex % 3) + un;
if (num < 3) {
cout << -1 << endl;
} else {
if (num % 3 == 0) {
cout << in + ex/3 + num/3 << endl;
} else {
cout << in + ex/3 + num/3 + 1 << endl;
}
}
}
}
}
}