답안 #643713

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
643713 2022-09-22T19:28:37 Z ParsaS Kitchen (BOI19_kitchen) C++14
100 / 100
19 ms 992 KB
// In the name of God
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
typedef long long ll;
const int N = 300 + 5, MOD = 1e9 + 7;
int n, A[N], B[N], k, m;
bitset<N * N> dp;
int dp2[N * N], suf[N * N + 10];

void solve() {
    cin >> n >> m >> k;
    for (int i = 0; i < n; i++)
        cin >> A[i];
    for (int i = 0; i < m; i++)
        cin >> B[i];
    if (*min_element(A, A + n) < k) {
        cout << "Impossible" << endl;
        return;
    }
    vector<int> b, vec;
    for (int i = 0; i < m; i++) {
        if (B[i] < n)
            b.pb(B[i]);
        else
            vec.pb(B[i]);
    }
    dp[0] = true;
    for (auto x : b) {
        dp |= dp << x;
    }
    fill(dp2, dp2 + N * N, -1e9);
    dp2[0] = 0;
    for (auto x : vec) {
        for (int s = N * N - 1; s >= x; s--) {
            dp2[s] = max(dp2[s - x] + 1, dp2[s]);
        }
    }
    suf[N * N] = -1;
    for (int i = N * N - 1; i >= 0; i--) {
        suf[i] = suf[i + 1];
        if (dp[i])
            suf[i] = i;
    }
    int sumA = accumulate(A, A + n, 0);
    int ans = 1e9 + 5;
    for (int s = 0; s < N * N; s++) {
        if (dp2[s] >= 0 && suf[max(0, max(sumA - s, n * (k - dp2[s])))] != -1) {
            ans = min(ans, s + suf[max(0, max(sumA - s, n * (k - dp2[s])))] - sumA);
        }
    }
    if (ans < 1e9) {
        cout << ans << endl;
    }
    else
        cout << "Impossible\n";
}

int32_t main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    solve();

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 984 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 984 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 2 ms 980 KB Output is correct
10 Correct 2 ms 980 KB Output is correct
11 Correct 2 ms 980 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 980 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 980 KB Output is correct
2 Correct 3 ms 968 KB Output is correct
3 Correct 3 ms 980 KB Output is correct
4 Correct 11 ms 980 KB Output is correct
5 Correct 4 ms 980 KB Output is correct
6 Correct 2 ms 988 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 4 ms 980 KB Output is correct
2 Correct 3 ms 988 KB Output is correct
3 Correct 1 ms 968 KB Output is correct
4 Correct 2 ms 980 KB Output is correct
5 Correct 0 ms 340 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 980 KB Output is correct
2 Correct 1 ms 984 KB Output is correct
3 Correct 1 ms 980 KB Output is correct
4 Correct 1 ms 980 KB Output is correct
5 Correct 1 ms 980 KB Output is correct
6 Correct 1 ms 340 KB Output is correct
7 Correct 1 ms 348 KB Output is correct
8 Correct 1 ms 980 KB Output is correct
9 Correct 2 ms 980 KB Output is correct
10 Correct 2 ms 980 KB Output is correct
11 Correct 2 ms 980 KB Output is correct
12 Correct 1 ms 980 KB Output is correct
13 Correct 1 ms 980 KB Output is correct
14 Correct 3 ms 980 KB Output is correct
15 Correct 3 ms 968 KB Output is correct
16 Correct 3 ms 980 KB Output is correct
17 Correct 11 ms 980 KB Output is correct
18 Correct 4 ms 980 KB Output is correct
19 Correct 2 ms 988 KB Output is correct
20 Correct 4 ms 980 KB Output is correct
21 Correct 3 ms 988 KB Output is correct
22 Correct 1 ms 968 KB Output is correct
23 Correct 2 ms 980 KB Output is correct
24 Correct 0 ms 340 KB Output is correct
25 Correct 16 ms 980 KB Output is correct
26 Correct 19 ms 984 KB Output is correct
27 Correct 9 ms 980 KB Output is correct
28 Correct 11 ms 992 KB Output is correct
29 Correct 19 ms 972 KB Output is correct
30 Correct 12 ms 980 KB Output is correct