solution.cpp 1.6 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
#include <iostream>
#include <algorithm>
using namespace std;
int Solution()
{
    int n, sum = 0, L[5] = {0}, m, M, W[5][10] = {0}, le, P, res = 0;
    for (int i = 0; i < 6; i++)
    {
        cin >> n;
        sum += n;
        for (int j = 0; j < n; j++)
        {
            cin >> m;
            L[m]++;
        }
    }
    cin >> M;
    int ww;
    for (int i = 0; i < M; i++)
    {
        cin >> le >> P;
        for (int j = 1; j <= P; j++)
        {
            cin >> ww;
            if (ww > W[le][j])
                W[le][j] = ww;
            if ((j + 1 > P) && P < 7)
                for (int k = j + 1; k <= 7; k++)
                    W[le][k] = W[le][k - 1];
        }
    }
    for (int i = 0; i <= L[4]; i++)
    {
        for (int j = 0; j <= (sum - L[1] - L[2] - i); j++)
        {
            for (int k = 0; k <= (sum - L[1] - (i + j)); k++)
            {
                for (int s = 0; s <= (sum - (i + j + k)); s++)
                {
                    int a, b, c, d;
                    if (i > 7)
                        a = 7;
                    else
                        a = i;
                    if (j > 7)
                        b = 7;
                    else
                        b = j;
                    if (k > 7)
                        c = 7;
                    else
                        c = k;
                    if (s > 7)
                        d = 7;
                    else
                        d = s;
                    res = max(res, W[4][a] + W[3][b] + W[2][c] + W[1][d]);
                }
            }
        }
    }
    return res;
}
int main()
{
    cout << Solution();
    return 0;
}