Codeforces Round 978 (Div. 2)
A
Bus to Pénjamo
Codeforces
800
原题
←B →
翻译中…

Ya vamos llegando a Péeeenjamoo ♫♫♫

翻译中…

There are $n$ families travelling to Pénjamo to witness Mexico's largest-ever "walking a chicken on a leash" marathon. The $i$-th family has $a_i$ family members. All families will travel using a single bus consisting of $r$ rows with $2$ 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 $\displaystyle\sum_{i=1}^{n}a_i \le 2r$.

翻译中…

Input

翻译中…

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

翻译中…

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

翻译中…

The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \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 $4$ happy people are colored green.

翻译中…

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

翻译中…

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

翻译中…

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

翻译中…

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

翻译中…

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

翻译中…

样例

Input #1
4
3 3
2 3 1
3 3
2 2 2
4 5
1 1 2 2
4 5
3 1 1 3
Output #1
4
6
6
6
InputCopy OutputCopy
题目信息
题号
2022A
时间限制
1 s
内存限制
256 MB
标签
构造
贪心
模拟
数学

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。