답안 #422778

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
422778 2021-06-10T12:11:16 Z aryan12 Kitchen (BOI19_kitchen) C++17
100 / 100
99 ms 972 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

mt19937_64 RNG(chrono::steady_clock::now().time_since_epoch().count());

void Solve() {
    int n, m, k;
    cin >> n >> m >> k;
    vector<int> a(n + 1), b(m + 1);
    for(int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for(int i = 1; i <= m; i++) {
        cin >> b[i];
    }
    for(int i = 1; i <= n; i++) {
        if(a[i] < k) {
            cout << "Impossible\n";
            return;
        }
    }
    int sum = 0;
    for(int i = 1; i <= m; i++) {
        sum += b[i];
    }
    vector<int> dp(sum + 1, INT_MIN);
    dp[0] = 0;
    for(int i = 1; i <= m; i++) {
        for(int j = sum - b[i]; j >= 0; j--) {
            dp[j + b[i]] = max(dp[j + b[i]], dp[j] + min(n, b[i]));
        }
    }
    int min_req = 0;
    for(int i = 1; i <= n; i++) {
        min_req += a[i];
    }
    /*for(int i = 0; i <= sum; i++) {
        cout << dp[i] << " ";
    }
    cout << "\n";*/
    for(int i = min_req; i <= sum; i++) {
        if(dp[i] >= n * k) {
            cout << i - min_req << "\n";
            return;
        }
    }
    cout << "Impossible\n";
} 

int32_t main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    Solve();
    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 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 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 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 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 65 ms 816 KB Output is correct
2 Correct 49 ms 716 KB Output is correct
3 Correct 55 ms 588 KB Output is correct
4 Correct 92 ms 972 KB Output is correct
5 Correct 99 ms 972 KB Output is correct
6 Correct 40 ms 716 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 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 332 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 0 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 0 ms 204 KB Output is correct
7 Correct 1 ms 204 KB Output is correct
8 Correct 1 ms 204 KB Output is correct
9 Correct 1 ms 332 KB Output is correct
10 Correct 1 ms 312 KB Output is correct
11 Correct 1 ms 312 KB Output is correct
12 Correct 1 ms 204 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 65 ms 816 KB Output is correct
15 Correct 49 ms 716 KB Output is correct
16 Correct 55 ms 588 KB Output is correct
17 Correct 92 ms 972 KB Output is correct
18 Correct 99 ms 972 KB Output is correct
19 Correct 40 ms 716 KB Output is correct
20 Correct 1 ms 204 KB Output is correct
21 Correct 1 ms 204 KB Output is correct
22 Correct 1 ms 204 KB Output is correct
23 Correct 1 ms 332 KB Output is correct
24 Correct 1 ms 204 KB Output is correct
25 Correct 47 ms 704 KB Output is correct
26 Correct 60 ms 716 KB Output is correct
27 Correct 19 ms 460 KB Output is correct
28 Correct 49 ms 716 KB Output is correct
29 Correct 67 ms 844 KB Output is correct
30 Correct 97 ms 956 KB Output is correct