time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Alice is playing with some stones.
Now there are three numbered heaps of stones. The first of them contains aa stones, the second of them contains bb stones and the third of them contains cc stones.
Each time she can do one of two operations:
- take one stone from the first heap and two stones from the second heap (this operation can be done only if the first heap contains at least one stone and the second heap contains at least two stones);
- take one stone from the second heap and two stones from the third heap (this operation can be done only if the second heap contains at least one stone and the third heap contains at least two stones).
She wants to get the maximum number of stones, but she doesn't know what to do. Initially, she has 00 stones. Can you help her?
Input
The first line contains one integer tt (1≤t≤1001≤t≤100) — the number of test cases. Next tt lines describe test cases in the following format:
Line contains three non-negative integers aa, bb and cc, separated by spaces (0≤a,b,c≤1000≤a,b,c≤100) — the number of stones in the first, the second and the third heap, respectively.
In hacks it is allowed to use only one test case in the input, so t=1t=1 should be satisfied.
Output
Print tt lines, the answers to the test cases in the same order as in the input. The answer to the test case is the integer — the maximum possible number of stones that Alice can take after making some operations.
Example
input
Copy
3 3 4 5 1 0 5 5 3 2
output
Copy
9 0 6
Note
For the first test case in the first test, Alice can take two stones from the second heap and four stones from the third heap, making the second operation two times. Then she can take one stone from the first heap and two stones from the second heap, making the first operation one time. The summary number of stones, that Alice will take is 99. It is impossible to make some operations to take more than 99 stones, so the answer is 99.
解题说明:水题,先取第三堆,再取第二堆,最后取第一堆。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
int main()
{
int times;
int a[3];
int t = 0;
scanf("%d", ×);
while (times--)
{
scanf("%d %d %d", &a[0], &a[1], &a[2]);
while (a[2] >= 2 && a[1] > 0)
{
t++;
a[2] -= 2;
a[1] -= 1;
}
while (a[1] > 1 && a[0] > 0)
{
t++;
a[0]--;
a[1] -= 2;
}
printf("%d\n", t * 3);
t = 0;
}
return 0;
}