CF2022A.Bus to Pénjamo

传统题 时间 2000 ms 内存 256 MiB 3 尝试 1 已通过 1 标签

Bus to Pénjamo

Ya vamos llegando a Péeeenjamoo ♫♫♫

There are nn families travelling to Pénjamo to witness Mexico's largest-ever "walking a chicken on a leash" marathon. The ii-th family has aia_i family members. All families will travel using a single bus consisting of rr rows with 22 seats each.

A person is considered happy if:

  • Another family member is seated in the same row as them, or
  • They are sitting alone in their row (with an empty seat next to them).

Determine the maximum number of happy people in an optimal seating arrangement. Note that everyone must be seated in the bus.

It is guaranteed that all family members will fit on the bus. Formally, it is guaranteed that umi=1nai2r\displaystyle um_{i=1}^{n}a_i \le 2r.

Input

Each test contains multiple test cases. The first line contains the number of test cases tt (1t10001 \le t \le 1000). The description of the test cases follows.

The first line of each test case contains two integers nn and rr (1n1001 \le n \le 100; 1r5001 \le r \le 500) — the number of families and the number of rows in the bus.

The second line contains nn integers a1,a2,,ana_1, a_2, \ldots, a_n (1ai101 \le a_i \le 10) — the number of family members in each family.

Output

For each test case, output the maximum number of happy people in an optimal seating arrangement.

Note

In the first test case, the two members of the first family can sit together in the first row, while the two members of the second family can sit together in the second row. The remaining member of the second family can sit in the third row along with a member of the third family. This seating arrangement is shown below, where the 44 happy people are colored green.

1\color{green}{1}
2\color{green}{2}
22 33

In the second test case, a possible seating arrangement with 66 happy people is shown below.

3\color{green}{3}
1\color{green}{1}
2\color{green}{2}

In the third test case, a possible seating arrangement with 66 happy people is shown below.

4\color{green}{4}
\color{green}{} 2\color{green}{2}
3\color{green}{3}
1\color{green}{1} \color{green}{}
\color{green}{}

Samples

4
3 3
2 3 1
3 3
2 2 2
4 5
1 1 2 2
4 5
3 1 1 3
4
6
6
6

在线编程 IDE

建议全屏模式获得最佳体验