제출 #1099363

#제출 시각아이디문제언어결과실행 시간메모리
1099363cpismylifeOwOKitchen (BOI19_kitchen)C++17
21 / 100
41 ms68652 KiB
#include <bits/stdc++.h>

using namespace std;

const long long mod = 1e9 + 7;
const int MaxN = 3e2 + 5;

int n, m, k;
int a[MaxN];
int b[MaxN];

void Inp()
{
    cin >> n >> m >> k;
    for (int x = 1; x <= n; x++)
    {
        cin >> a[x];
    }
    for (int x = 1; x <= m; x++)
    {
        cin >> b[x];
    }
}

int F[MaxN][MaxN * MaxN + 5];

void Exc()
{
    int suma = 0, sumb = 0;
    for (int x = 1; x <= n; x++)
    {
        suma += a[x];
        if (a[x] < k)
        {
            cout << "Impossible";
            return;
        }
    }
    for (int x = 1; x <= m; x++)
    {
        sumb += b[x];
    }
    for (int x = 1; x <= m; x++)
    {
        for (int y = 0; y < b[x]; y++)
        {
            F[x][y] = F[x - 1][y];
        }
        for (int y = b[x]; y <= sumb; y++)
        {
            F[x][y] = max(F[x - 1][y], F[x - 1][y - b[x]] + min(b[x], n));
        }
    }
    for (int x = suma; x <= sumb; x++)
    {
        if (F[m][x] >= n * k)
        {
            cout << x - suma;
            return;
        }
    }
    cout << "Impossible";
}

int main()
{
    //freopen("F.INP", "r", stdin);
    //freopen("F.OUT", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int test = 1;
    //cin >> test;
    for (int x = 1; x <= test; x++)
    {
        Inp();
        Exc();
    }
    return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...