Submission #1111149

# Submission time Handle Problem Language Result Execution time Memory
1111149 2024-11-11T15:22:17 Z Ghulam_Junaid Kitchen (BOI19_kitchen) C++17
100 / 100
273 ms 4680 KB
#include <bits/stdc++.h>
using namespace std;
 
const int N = 305;
const int SM = N * N;
int n, m, k, a[N], b[N], dp_more[SM], dp_less[SM];
 
int main(){
    cin >> n >> m >> k;
    int need = 0;
    for (int i = 0; i < n; i ++)
        cin >> a[i], need += a[i];
    for (int i = 0; i < m; i ++)
        cin >> b[i];
 
    sort(b, b + m);
    sort(a, a + n);
 
    if (a[0] < k){
        cout << "Impossible\n";
        return 0;
    }
 
    memset(dp_more, -1, sizeof dp_more);
    memset(dp_less, -1, sizeof dp_less);
 
    dp_more[0] = dp_less[0] = 0;
    set<int> created;
    created.insert(0);
 
    for (int i = 0; i < m; i ++){
        for (int sm = SM - 1; sm >= b[i]; sm --){
            if (b[i] > n and ~dp_more[sm - b[i]]){
                dp_more[sm] = max(dp_more[sm], dp_more[sm - b[i]] + 1);
            }
            else if (b[i] <= n and ~dp_less[sm - b[i]]){
                dp_less[sm] = max(dp_less[sm], dp_less[sm - b[i]] + 1);
                created.insert(sm);
            }
        }
    }
 
 
    int ans = 1e9;
    for (int sm = 0; sm < SM; sm++){
        int x = dp_more[sm];
        if (x == -1) continue;
        
        int left = max((k - x) * n, need - sm);
        left = max(0, left);
 
        auto ub = created.upper_bound(left - 1);
        if (ub == created.end())
            continue;
 
        int used = (*ub) + sm;
        ans = min(ans, used - need);
    }
 
    if (ans == 1e9)
        cout << "Impossible\n";
    else
        cout << ans << endl;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1104 KB Output is correct
2 Correct 1 ms 1104 KB Output is correct
3 Correct 2 ms 1104 KB Output is correct
4 Correct 2 ms 1104 KB Output is correct
5 Correct 1 ms 964 KB Output is correct
6 Correct 1 ms 504 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 1104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1104 KB Output is correct
2 Correct 1 ms 1104 KB Output is correct
3 Correct 2 ms 1104 KB Output is correct
4 Correct 2 ms 1104 KB Output is correct
5 Correct 1 ms 964 KB Output is correct
6 Correct 1 ms 504 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 1104 KB Output is correct
9 Correct 3 ms 1104 KB Output is correct
10 Correct 2 ms 1104 KB Output is correct
11 Correct 3 ms 1104 KB Output is correct
12 Correct 3 ms 1180 KB Output is correct
13 Correct 3 ms 1104 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 38 ms 2376 KB Output is correct
2 Correct 106 ms 2684 KB Output is correct
3 Correct 164 ms 3144 KB Output is correct
4 Correct 157 ms 3400 KB Output is correct
5 Correct 273 ms 4680 KB Output is correct
6 Correct 55 ms 2120 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 4 ms 1104 KB Output is correct
2 Correct 5 ms 948 KB Output is correct
3 Correct 6 ms 1280 KB Output is correct
4 Correct 5 ms 1104 KB Output is correct
5 Correct 1 ms 336 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 2 ms 1104 KB Output is correct
2 Correct 1 ms 1104 KB Output is correct
3 Correct 2 ms 1104 KB Output is correct
4 Correct 2 ms 1104 KB Output is correct
5 Correct 1 ms 964 KB Output is correct
6 Correct 1 ms 504 KB Output is correct
7 Correct 1 ms 336 KB Output is correct
8 Correct 1 ms 1104 KB Output is correct
9 Correct 3 ms 1104 KB Output is correct
10 Correct 2 ms 1104 KB Output is correct
11 Correct 3 ms 1104 KB Output is correct
12 Correct 3 ms 1180 KB Output is correct
13 Correct 3 ms 1104 KB Output is correct
14 Correct 38 ms 2376 KB Output is correct
15 Correct 106 ms 2684 KB Output is correct
16 Correct 164 ms 3144 KB Output is correct
17 Correct 157 ms 3400 KB Output is correct
18 Correct 273 ms 4680 KB Output is correct
19 Correct 55 ms 2120 KB Output is correct
20 Correct 4 ms 1104 KB Output is correct
21 Correct 5 ms 948 KB Output is correct
22 Correct 6 ms 1280 KB Output is correct
23 Correct 5 ms 1104 KB Output is correct
24 Correct 1 ms 336 KB Output is correct
25 Correct 16 ms 1104 KB Output is correct
26 Correct 20 ms 1104 KB Output is correct
27 Correct 19 ms 1404 KB Output is correct
28 Correct 49 ms 2056 KB Output is correct
29 Correct 19 ms 1104 KB Output is correct
30 Correct 94 ms 2848 KB Output is correct