Submission #398697

# Submission time Handle Problem Language Result Execution time Memory
398697 2021-05-04T17:55:52 Z iulia13 Kitchen (BOI19_kitchen) C++14
100 / 100
28 ms 972 KB
#include <iostream>
#include <algorithm>
using namespace std;
const int nmax = 305;
int dp[2][nmax * nmax];
int b[nmax];
int main()
{
    ///bagi artificial o singura data un chef la o anumita mancarica ca te int doar ca suma timp chefi >= suma timpi mancare dupa
    ///=> un chef contribuie la min(n, bi) mancarici
    ///tb n*k in total minim
    ///dp[x] = x ore chefi ; contributie artificiala
    ///dp[i][x] -> primii i chefi x ore => dp[i+1][x] = dp[i][x] (nu te int) + dp[i][x - b[i + 1]] => 0/1 dp
    int A, a, n, m, k, i, j, B;
    cin >> n >> m >> k;
    A = B = 0;
    for (i = 1; i <= n; i++)
    {
        cin >> a; A += a;
        if (a < k)
        {
            cout << "Impossible";
            return 0;
        }
    }
    for (j = 1; j <= m; j++)
        cin >> b[j], B += b[j];
    for (i = 0; i <= 1; i++)
        for (j = 0; j <= B; j++)
            dp[i][j] = -2e9;
    dp[0][0] = 0;
    dp[1][0] = 0;
    sort(b + 1, b + m + 1);
    reverse(b + 1, b + m + 1);
    for (i = 1; i <= m; i++)
        for (j = b[i]; j <= B; j++)
            dp[i % 2][j] = max(dp[1 - i % 2][j - b[i]] + min(b[i], n), dp[1 - i % 2][j]);
    for (i = A; i <= B; i++)
        if (dp[m % 2][i] >= n * k)
        {
            cout << i - A;
            return 0;
        }
    cout << "Impossible";
    return 0;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 216 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 216 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 19 ms 804 KB Output is correct
2 Correct 15 ms 716 KB Output is correct
3 Correct 16 ms 588 KB Output is correct
4 Correct 27 ms 952 KB Output is correct
5 Correct 28 ms 972 KB Output is correct
6 Correct 12 ms 588 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 304 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 216 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 304 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 332 KB Output is correct
11 Correct 1 ms 204 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 19 ms 804 KB Output is correct
15 Correct 15 ms 716 KB Output is correct
16 Correct 16 ms 588 KB Output is correct
17 Correct 27 ms 952 KB Output is correct
18 Correct 28 ms 972 KB Output is correct
19 Correct 12 ms 588 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 304 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 204 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 14 ms 716 KB Output is correct
26 Correct 18 ms 808 KB Output is correct
27 Correct 6 ms 460 KB Output is correct
28 Correct 14 ms 716 KB Output is correct
29 Correct 23 ms 844 KB Output is correct
30 Correct 28 ms 968 KB Output is correct