Submission #603345

# Submission time Handle Problem Language Result Execution time Memory
603345 2022-07-24T03:50:21 Z nguyentu Kitchen (BOI19_kitchen) C++14
100 / 100
140 ms 100460 KB
#include <bits/stdc++.h>

#pragma GCC target("avx2")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")

using namespace std;

#define ii pair<int , int>  
#define iv pair<ii , ii>
#define iii pair<int , ii>
#define fi first
#define se second
const int inf = 1e9 + 7;
const int MAX_N = 3e2 + 7;
const int MOD = 1e9 + 7;
const int MAX_V = 300 * 301;

int n , m , K;
int f[MAX_N][MAX_N*MAX_N];
int a[MAX_N];
int b[MAX_N];
signed main() {
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    cin >> n >> m >> K;
    int W = 0 , w = 0;
    for (int i = 1 ; i <= n ; i++) {
        cin >> a[i];
        if (a[i] < K) {
            cout << "Impossible";
            return 0;
        }
        W += a[i];
    }
    for (int i = 1 ; i <= m ; i++) {
        cin >> b[i];
        w += b[i];
    }
    if (W > w || K > m) {
        cout << "Impossible";
        return 0;
    }
    for (int i = 0 ; i <= m ; i++) {
        for (int j = 0 ; j <= w ; j++) {
            f[i][j] = -inf;
        }
    }
    f[0][0] = 0;
    for (int i = 1 ; i <= m ; i++) {
        for (int j = 0 ; j <= w ; j++) {
            f[i][j] = f[i - 1][j];
            if (j - b[i] >= 0) {
                f[i][j] = max(f[i][j] , f[i - 1][j - b[i]] + min(b[i] , n));
            }
        }
    }
    int ans = inf;
    for (int i = W ; i <= w ; i++) {
        if (f[m][i] >= n*K) {
            ans = min(ans , i - W);
        }
    }
    if (ans == inf) cout << "Impossible";
    else cout << ans;
    return 0;
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 120 ms 68976 KB Output is correct
2 Correct 73 ms 51720 KB Output is correct
3 Correct 81 ms 58104 KB Output is correct
4 Correct 137 ms 98592 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
6 Correct 77 ms 42060 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 1 ms 724 KB Output is correct
5 Correct 0 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 340 KB Output is correct
2 Correct 0 ms 340 KB Output is correct
3 Correct 1 ms 340 KB Output is correct
4 Correct 1 ms 340 KB Output is correct
5 Correct 1 ms 340 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 1 ms 212 KB Output is correct
8 Correct 1 ms 212 KB Output is correct
9 Correct 1 ms 596 KB Output is correct
10 Correct 1 ms 460 KB Output is correct
11 Correct 1 ms 340 KB Output is correct
12 Correct 1 ms 340 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 120 ms 68976 KB Output is correct
15 Correct 73 ms 51720 KB Output is correct
16 Correct 81 ms 58104 KB Output is correct
17 Correct 137 ms 98592 KB Output is correct
18 Correct 1 ms 212 KB Output is correct
19 Correct 77 ms 42060 KB Output is correct
20 Correct 1 ms 596 KB Output is correct
21 Correct 1 ms 596 KB Output is correct
22 Correct 1 ms 596 KB Output is correct
23 Correct 1 ms 724 KB Output is correct
24 Correct 0 ms 212 KB Output is correct
25 Correct 77 ms 50540 KB Output is correct
26 Correct 85 ms 62540 KB Output is correct
27 Correct 33 ms 19064 KB Output is correct
28 Correct 79 ms 51484 KB Output is correct
29 Correct 98 ms 70116 KB Output is correct
30 Correct 140 ms 100460 KB Output is correct