WA 5,6,9,10点
求大佬看看 算了半天所各个情况的统计可能,人已经麻了
#include<iostream>
#include<cmath>
#include<algorithm>
using namespace std;
int t, n, a, f[4], cnt;
long long ans;
int in() {
int k = 0;
char c = getchar();
while (c < '0' || c>'9')
{
c = getchar();
}
while (c >= '0' && c <= '9') k = k * 10 + c - '0', c = getchar();
return k;
}
void decompose(int a)
{
f[3] += a / 3;
if (a % 3 == 1)f[1]++;
if (a % 3 == 2)f[2]++;
return;
}
void solve()
{
if (f[3] <= f[1])
{
ans = ans + f[1] + f[2];
cout << ans << '\n';
return;
}
else//f[1]少于f[3],后面同理
{
ans += f[1];
f[3] -= f[1];
}
if (f[3] <= f[2] * 2)
{
ans += f[3];
ans += f[2] - f[3] / 2;
cout << ans << '\n';
return;
}
else
{
ans += f[2] * 2;
f[3] -= f[2] * 2;
long long z = (f[3] - 1) / 4;
ans += 3 * z;
z = (f[3] - 1) % 4;
if (z == 0 || z == 1) ans += 2;
else ans += 3;
cout << ans << '\n';
return;
}
}
int main(){
t = in();
while (t--)
{
ans = 0;
n = in();
f[1] = 0;
f[2] = 0;
f[3] = 0;
for (int i = 1;i <= n;i++)
{
a = in();
decompose(a);
}
solve();
}
return 0;
}