답안 #906237

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
906237 2024-01-13T20:33:43 Z n3rm1n Kitchen (BOI19_kitchen) C++17
100 / 100
68 ms 108120 KB
#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
const int MAXN = 305, MAXH = 90005;
void speed()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int n, m, k;
int a[MAXN], b[MAXN];
int diverse = 0, hours = 0;
int max_used = 0;
void read()
{
    cin >> n >> m >> k;
    int no = 0;
    for (int i = 1; i <= n; ++ i)
    {
        cin >> a[i];
        hours += a[i];
        if(a[i] < k)no = 1;
    }
    diverse = k * n;
    for (int i = 1; i <= m; ++ i)
    {
        cin >> b[i];
        max_used += b[i];
    }
    if(no == 1)
    {
        cout << "Impossible" << endl;
        exit(0);
    }
}
int dp[MAXN][MAXH/**the number of used hours*/];
void solve()
{
    memset(dp, -1, sizeof(dp));
    dp[0][0] = 0;
    for (int i = 1; i <= m; ++ i)
    {
        dp[i][0] = 0;
        for (int j = 0; j <= max_used; ++ j)
        {
            if(dp[i][j] < dp[i-1][j])dp[i][j] = max(dp[i][j], dp[i-1][j]);
            int adding = min(b[i], n);
            if(j >= b[i])
            {
                if(dp[i-1][j-b[i]] == -1)continue;
                int neww = dp[i-1][j - b[i]] + adding;
                dp[i][j] = max(dp[i][j], neww);
            }
        }
    }
    for (int i = hours; i <= max_used; ++ i)
    {
        if(dp[m][i] >= diverse)
        {
            cout << i-hours << endl;
            return;
        }
    }
    cout << "Impossible" << endl;
}
int main()
{
    speed();

    read();
    solve();
    return 0;
}
/***
4--
4 2 1
12 43 61 11
98 130
3--
4 2 1
12 43 61 11
30 15 5
6 6 5 7 6 7 7 7 7 6 7 6 7 6 6 6 5 6 6 7 7 6 5 7 7 5 5 5 5 7
12 6 11 8 8 11 9 6 18 20 21 18 19 20 10


*/
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 107868 KB Output is correct
2 Correct 19 ms 107868 KB Output is correct
3 Correct 18 ms 107868 KB Output is correct
4 Correct 19 ms 107776 KB Output is correct
5 Correct 19 ms 107864 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 440 KB Output is correct
8 Correct 19 ms 107784 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 107868 KB Output is correct
2 Correct 19 ms 107868 KB Output is correct
3 Correct 18 ms 107868 KB Output is correct
4 Correct 19 ms 107776 KB Output is correct
5 Correct 19 ms 107864 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 440 KB Output is correct
8 Correct 19 ms 107784 KB Output is correct
9 Correct 19 ms 107868 KB Output is correct
10 Correct 17 ms 107820 KB Output is correct
11 Correct 18 ms 107868 KB Output is correct
12 Correct 19 ms 107868 KB Output is correct
13 Correct 18 ms 107800 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 52 ms 107868 KB Output is correct
2 Correct 35 ms 107884 KB Output is correct
3 Correct 38 ms 107884 KB Output is correct
4 Correct 52 ms 107884 KB Output is correct
5 Correct 53 ms 107804 KB Output is correct
6 Correct 34 ms 107868 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 18 ms 107868 KB Output is correct
2 Correct 18 ms 108120 KB Output is correct
3 Correct 18 ms 107868 KB Output is correct
4 Correct 18 ms 108064 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 19 ms 107868 KB Output is correct
2 Correct 19 ms 107868 KB Output is correct
3 Correct 18 ms 107868 KB Output is correct
4 Correct 19 ms 107776 KB Output is correct
5 Correct 19 ms 107864 KB Output is correct
6 Correct 1 ms 348 KB Output is correct
7 Correct 1 ms 440 KB Output is correct
8 Correct 19 ms 107784 KB Output is correct
9 Correct 19 ms 107868 KB Output is correct
10 Correct 17 ms 107820 KB Output is correct
11 Correct 18 ms 107868 KB Output is correct
12 Correct 19 ms 107868 KB Output is correct
13 Correct 18 ms 107800 KB Output is correct
14 Correct 52 ms 107868 KB Output is correct
15 Correct 35 ms 107884 KB Output is correct
16 Correct 38 ms 107884 KB Output is correct
17 Correct 52 ms 107884 KB Output is correct
18 Correct 53 ms 107804 KB Output is correct
19 Correct 34 ms 107868 KB Output is correct
20 Correct 18 ms 107868 KB Output is correct
21 Correct 18 ms 108120 KB Output is correct
22 Correct 18 ms 107868 KB Output is correct
23 Correct 18 ms 108064 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 35 ms 107868 KB Output is correct
26 Correct 41 ms 107868 KB Output is correct
27 Correct 25 ms 107868 KB Output is correct
28 Correct 37 ms 107852 KB Output is correct
29 Correct 46 ms 107868 KB Output is correct
30 Correct 68 ms 107860 KB Output is correct