#P11044. [蓝桥杯 2024 省 Java B] 食堂

[蓝桥杯 2024 省 Java B] 食堂

Problem Description

In S School, there are a2a_2 double rooms, a3a_3 triple rooms, and a4a_4 quadruple rooms. In the canteen, there are b4b_4 four-seat tables and b6b_6 six-seat tables. The school wants to arrange the students to eat in the canteen, and it must be ensured that all students from the same dorm room sit at the same table. What is the maximum number of students that can be served at the same time?

Input Format

This problem uses multiple test cases.

The input has q+1q + 1 lines.

The first line is a positive integer qq, which is the number of test cases.

The next qq lines each contain five non-negative integers a2,a3,a4,b4,b6a_2, a_3, a_4, b_4, b_6, describing one test case.

Output Format

Output qq lines. Each line contains one integer, the answer for the corresponding test case.

2
3 0 1 0 1
0 2 2 1 1
6
10

Hint

[Sample Explanation]

For the first test case, there is only one six-seat table, so at most three double rooms can be arranged to eat. The answer is (2+2+2)=6(2 + 2 + 2) = 6.

For the second test case, use one six-seat table to seat two triple rooms, and use one four-seat table to seat one quadruple room. The answer is (3+3)+(4)=10(3 + 3) + (4) = 10.

[Constraints and Notes for Test Cases]

For 20%20\% of the test cases, it is guaranteed that a2+a3+a48a_2 + a_3 + a_4 \leq 8.

For 100%100\% of the test cases, it is guaranteed that q100q \leq 100, and b4+b6a2+a3+a4100b_4 + b_6 \leq a_2 + a_3 + a_4 \leq 100.

Translated by ChatGPT 5