답안 #874157

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
874157 2023-11-16T11:14:47 Z vjudge1 Kitchen (BOI19_kitchen) C++17
100 / 100
38 ms 824 KB
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

const int MAXN = 300 + 5;

int dp[MAXN * MAXN];

#define ONLINE_JUDGE
void solve() {
    fill_n(&dp[0], MAXN * MAXN, int(-1E9));

    int n, m, k;
    cin >> n >> m >> k;

    vector <int> a(n);
    for(int &i : a)
        cin >> i;

    vector <int> b(m);
    for(int &i : b)
        cin >> i;

    bool check = true;
    for(int &i : a)
        check &= (k <= i);

    if(!check) {
        return cout << "Impossible", void();
    }

    dp[0] = 0;
    for(int i = 0; i < m; i++) {
        for(int j = MAXN * MAXN -1; j >= b[i]; j--) {
            dp[j] = max(dp[j], dp[j - b[i]] + min(b[i], n));
        }
    }

    int cev = MAXN * MAXN +1, suma = accumulate(a.begin(), a.end(), 0);
    for(int i = MAXN * MAXN -1; i >= suma; i--) {
        if(dp[i] >= n * k) {
            cev = i;
        }
    }

    if(cev == MAXN * MAXN +1)
        cout << "Impossible";
    else 
        cout << cev - suma;
    
    return;
}

signed main() {
    #ifndef ONLINE_JUDGE
        freopen(".in", "r", stdin);
        freopen(".out", "w", stdout);
    #endif

    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);

    int t = 1; //cin >> t;
    for(int i = 1; i <= t; i++) {
        solve();
    }

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 820 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 696 KB Output is correct
6 Correct 0 ms 600 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 820 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 696 KB Output is correct
6 Correct 0 ms 600 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 2 ms 820 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 28 ms 600 KB Output is correct
2 Correct 25 ms 604 KB Output is correct
3 Correct 38 ms 824 KB Output is correct
4 Correct 33 ms 604 KB Output is correct
5 Correct 31 ms 600 KB Output is correct
6 Correct 23 ms 600 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 5 ms 604 KB Output is correct
2 Correct 5 ms 604 KB Output is correct
3 Correct 6 ms 604 KB Output is correct
4 Correct 5 ms 600 KB Output is correct
5 Correct 0 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 820 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 696 KB Output is correct
6 Correct 0 ms 600 KB Output is correct
7 Correct 1 ms 604 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 2 ms 604 KB Output is correct
10 Correct 2 ms 600 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 2 ms 820 KB Output is correct
14 Correct 28 ms 600 KB Output is correct
15 Correct 25 ms 604 KB Output is correct
16 Correct 38 ms 824 KB Output is correct
17 Correct 33 ms 604 KB Output is correct
18 Correct 31 ms 600 KB Output is correct
19 Correct 23 ms 600 KB Output is correct
20 Correct 5 ms 604 KB Output is correct
21 Correct 5 ms 604 KB Output is correct
22 Correct 6 ms 604 KB Output is correct
23 Correct 5 ms 600 KB Output is correct
24 Correct 0 ms 604 KB Output is correct
25 Correct 23 ms 604 KB Output is correct
26 Correct 27 ms 600 KB Output is correct
27 Correct 17 ms 600 KB Output is correct
28 Correct 27 ms 600 KB Output is correct
29 Correct 27 ms 604 KB Output is correct
30 Correct 33 ms 604 KB Output is correct