답안 #1005503

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
1005503 2024-06-22T13:58:10 Z anango Kitchen (BOI19_kitchen) C++17
100 / 100
29 ms 1116 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main() {
    //freopen("input.txt","r", stdin);
    //freopen("output.txt","w",stdout);
    int n,m,k;
    cin >> n >> m >> k;
    int fail=0;
    vector<int> a,b;
    for (int i=0; i<n; i++) {
        int x;
        cin >> x;
        if (x<k) {
            fail=1;
        }

        a.push_back(x);

    }
    for (int i=0; i<m; i++) {
        int x;
        cin >> x;
        b.push_back(x);
    }
    if (fail) {
        cout << "Impossible" << endl;
        return 0;
    }
    sort(b.begin(), b.end());
    int S = accumulate(b.begin(), b.end(), (int)0)+1;
    int T = accumulate(a.begin(), a.end(), (int)0);
    int dp[S];
    for (int j=0; j<=S; j++) {
        dp[j] = -1;
    }
    dp[0] = 0;
    for (int i=0; i<m; i++) {
        int val = b[i]; 
        for (int j=S; j>=val; j--) {
            if (dp[j-val]!=-1) {
                dp[j] = max(dp[j],dp[j-val]+min(n,val));
            }
        }
    }
    int ans = -1;
    for (int i=T; i<=S; i++) {
        //cout << i <<" " << dp[i] << endl;
        if (dp[i]>=n*k) {
            ans=i-T;
            break;
        }
    }
    if (ans==-1) {
        cout << "Impossible" << endl;
    }
    else {
        cout << ans << endl;
    }
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 25 ms 856 KB Output is correct
2 Correct 12 ms 860 KB Output is correct
3 Correct 13 ms 604 KB Output is correct
4 Correct 22 ms 1092 KB Output is correct
5 Correct 23 ms 1116 KB Output is correct
6 Correct 13 ms 824 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 1 ms 600 KB Output is correct
4 Correct 1 ms 344 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 1 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 0 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 1 ms 344 KB Output is correct
13 Correct 0 ms 348 KB Output is correct
14 Correct 25 ms 856 KB Output is correct
15 Correct 12 ms 860 KB Output is correct
16 Correct 13 ms 604 KB Output is correct
17 Correct 22 ms 1092 KB Output is correct
18 Correct 23 ms 1116 KB Output is correct
19 Correct 13 ms 824 KB Output is correct
20 Correct 0 ms 348 KB Output is correct
21 Correct 1 ms 348 KB Output is correct
22 Correct 1 ms 600 KB Output is correct
23 Correct 1 ms 344 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 21 ms 860 KB Output is correct
26 Correct 18 ms 936 KB Output is correct
27 Correct 6 ms 604 KB Output is correct
28 Correct 14 ms 844 KB Output is correct
29 Correct 25 ms 976 KB Output is correct
30 Correct 29 ms 860 KB Output is correct