Codeforces 라운드 # 565 (사업부. 3) B. 병합 그것!

제목 : https://codeforces.com/contest/1176/problem/B
아이디어 : 그리
\ (A_I \; 개조 \; 3 \) 만 \ (0 \) \ (1 \) \ (2 \) 세 케이스
하자 (\; MOD \ 3 = 0 \ SUM \)\ (0 \) \ (1 \)\ (2 \) \ (1 \)\ (1 \)(\ 1 \) \ (2 \)\ (2 \)\ (2 \) 4 개의 케이스
선택된 저소비들을 선택할

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    int T;
    scanf("%d",&T);
    int n;
    int a;
    while(T--)
    {
        scanf("%d",&n);
        int ans=0;
        int b1=0;
        int b2=0;
        while(n--)
        {
            scanf("%d",&a);
            if(a%3==0) ans++;
            else if(a%3==1) b1++;
            else if(a%3==2) b2++;
        }
        if(b1<b2) ans+=b1,b2-=b1,ans+=b2/3;
        else ans+=b2,b1-=b2,ans+=b1/3;
        printf("%d\n",ans);
    }
    return 0;
}

추천

출처www.cnblogs.com/c4Lnn/p/12113823.html