답안 #493040

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
493040 2021-12-10T03:54:17 Z wiwiho Kitchen (BOI19_kitchen) C++14
9 / 100
105 ms 262148 KB
#include <bits/stdc++.h>

#define printv(a, b) {\
    for(auto pv : a) b << pv << " ";\
    b << "\n";\
}

using namespace std;

typedef long long ll;

const ll MAX = INT_MAX;

void nosol(){
    cout << "Impossible\n";
    exit(0);
}

int n, m, k;
vector<int> a;
vector<int> b;
ll sa = 0;

const int SZ = 300;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cerr.tie(0);

    cin >> n >> m >> k;
    a.resize(n + 1);
    b.resize(m + 1);

    ll sb = 0;
    for(int i = 1; i <= n; i++) cin >> a[i], sa += a[i];
    for(int i = 1; i <= m; i++) cin >> b[i], sb += b[i];
    sort(a.begin() + 1, a.end(), greater<>());
    sort(b.begin() + 1, b.end(), greater<>());
    
    if(k > m || sa > sb){
        nosol();
    }

    for(int i = 1; i <= n; i++) if(a[i] < k) nosol();

    vector<vector<ll>> dp(m + 1, vector<ll>((m + 1) * SZ + 10, -MAX));
    dp[0][0] = 0;
    for(int i = 1; i <= m; i++){
        vector<vector<ll>> dp2 = dp;

        int cnt = 1;
        while(i < m && b[i] == b[i + 1]) i++, cnt++;
        
        for(int t = 1; t <= cnt; t++){
            for(int j = 0; j + t <= m; j++){
                for(int s = 0; s <= m * SZ; s++){
                    
                    ll tmp = MAX;
                    if(j + t < k - 1) tmp = dp[j][s];
                    else if(j + t >= k) tmp = dp[j][s] + (j + t) * b[i] + j;
                    else tmp = dp[j][s] + t * b[i];
                    
                    dp2[j + 1][s + b[i]] = max(dp2[j + 1][s + b[i]], tmp);
                }
            }
        }

        dp.swap(dp2);
    }

    ll ans = MAX;
    for(int i = k; i <= m; i++){
        for(int j = sa; j <= m * SZ; j++){
            if(dp[i][j] >= n * k) ans = min(ans, j - sa);
        }
    }
    if(ans == MAX) nosol();
    cout << ans << "\n";

    return 0;
}
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 312 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 312 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 3 ms 1524 KB Output is correct
10 Correct 3 ms 1556 KB Output is correct
11 Correct 3 ms 1524 KB Output is correct
12 Incorrect 3 ms 1524 KB Output isn't correct
13 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 105 ms 262148 KB Execution killed with signal 9
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 26 ms 8268 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Correct 0 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 312 KB Output is correct
7 Correct 0 ms 204 KB Output is correct
8 Correct 0 ms 204 KB Output is correct
9 Correct 3 ms 1524 KB Output is correct
10 Correct 3 ms 1556 KB Output is correct
11 Correct 3 ms 1524 KB Output is correct
12 Incorrect 3 ms 1524 KB Output isn't correct
13 Halted 0 ms 0 KB -