답안 #340186

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
340186 2020-12-27T09:14:37 Z blue Kitchen (BOI19_kitchen) C++11
100 / 100
41 ms 748 KB
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

//9 pts: 1 <= M <= 2
/*
int main()
{
    int N, M, K;
    cin >> N >> M >> K;

    int A[N], B[M];
    int Asum = 0;
    bool any1 = 0;
    for(int i = 0; i < N; i++)
    {
        cin >> A[i];
        Asum += A[i];
        if(A[i] == 1) any1 = 1;
    }
    for(int j = 0; j < M; j++) cin >> B[j];

    if(M == 1)
    {
        if(K == 1 && B[0] >= Asum) cout << B[0] - Asum << '\n';
        else cout << "Impossible\n";
    }
    else if(M == 2)
    {
        if(K == 1)
        {
            if(B[0] > B[1]) swap(B[0], B[1]);
            if(Asum <= B[0]) cout << B[0] - Asum << '\n';
            else if(Asum <= B[1]) cout << B[1] - Asum << '\n';
            else if(Asum <= B[0] + B[1]) cout << B[0] + B[1] - Asum << '\n';
            else cout << "Impossible\n";
        }
        else if(K == 2)
        {
            if(!any1 && B[0] >= N && B[1] >= N && B[0] + B[1] >= Asum) cout << B[0] + B[1] - Asum << '\n';
            else cout << "Impossible\n";
        }
        else cout << "Impossible\n";
    }
}
*/

//20 pts: K = 1
/*
int main()
{
    int N, M, K;
    cin >> N >> M >> K;

    int A[N], B[M];
    int Asum = 0;
    for(int i = 0; i < N; i++)
    {
        cin >> A[i];
        Asum += A[i];
    }
    for(int j = 0; j < M; j++) cin >> B[j];

    vector<int> possible(90001, 0);
    possible[0] = 1;
    int res = 90000;
    for(int j = 0; j < M; j++)
    {
        for(int i = 90000; i >= B[j]; i--)
        {
            if(!possible[i - B[j]]) continue;
            possible[i] = 1;
            if(i >= Asum) res = min(res, i - Asum);
        }
    }
    if(res == 90000) cout << "Impossible\n";
    else cout << res << '\n';
}
*/

/*
Condition for value K, meals 1, 2, ... N and chefs* 1, 2, ... y to be compatible  (* - chefs are re-numbered)
A[i] >= K
sum{j:chefs | max(B[j], N)} >= N*K
sum{j:chefs | B[j]} >= sum{i:meals | A[i]}
To minimize: sum{j:chefs | B[j]} - sum{i:meals | A[i]
*/

//100 pts
int main()
{
    int N, M, K;
    cin >> N >> M >> K;

    int A[N], B[M];
    bool impossible = 0;
    int Asum = 0;
    for(int i = 0; i < N; i++)
    {
        cin >> A[i];
        Asum += A[i];
        if(A[i] < K) impossible = 1;
    }
    for(int j = 0; j < M; j++) cin >> B[j];
    if(impossible)
    {
        cout << "Impossible\n";
        return 0;
    }
    //vector<bool> chef_sum(90001, 0);
    //chef_sum[0] = 1;
    vector<int> variety_sum(90001, -1); //sum over all dishes for number of different chefs for given total chef time sum
    variety_sum[0] = 0;

    for(int j = 0; j < M; j++)
    {
        for(int i = 90000; i >= B[j]; i--)
        {
            if(variety_sum[i - B[j]] >= 0)
            {
                variety_sum[i] = max(variety_sum[i], variety_sum[i - B[j]] + min(B[j], N));
            }
        }
    }

    for(int i = Asum; i <= 90000; i++)
    {
        if(variety_sum[i] >= N*K)
        {
            cout << i - Asum << '\n';
            return 0;
        }
    }
    cout << "Impossible\n";
}
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 620 KB Output is correct
2 Correct 1 ms 620 KB Output is correct
3 Correct 1 ms 620 KB Output is correct
4 Correct 1 ms 620 KB Output is correct
5 Correct 1 ms 620 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 620 KB Output is correct
2 Correct 1 ms 620 KB Output is correct
3 Correct 1 ms 620 KB Output is correct
4 Correct 1 ms 620 KB Output is correct
5 Correct 1 ms 620 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 620 KB Output is correct
9 Correct 3 ms 620 KB Output is correct
10 Correct 3 ms 620 KB Output is correct
11 Correct 3 ms 620 KB Output is correct
12 Correct 3 ms 620 KB Output is correct
13 Correct 3 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 37 ms 620 KB Output is correct
2 Correct 36 ms 748 KB Output is correct
3 Correct 41 ms 620 KB Output is correct
4 Correct 41 ms 628 KB Output is correct
5 Correct 40 ms 620 KB Output is correct
6 Correct 30 ms 620 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 6 ms 748 KB Output is correct
2 Correct 7 ms 620 KB Output is correct
3 Correct 6 ms 640 KB Output is correct
4 Correct 6 ms 620 KB Output is correct
5 Correct 1 ms 364 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 620 KB Output is correct
2 Correct 1 ms 620 KB Output is correct
3 Correct 1 ms 620 KB Output is correct
4 Correct 1 ms 620 KB Output is correct
5 Correct 1 ms 620 KB Output is correct
6 Correct 1 ms 364 KB Output is correct
7 Correct 1 ms 364 KB Output is correct
8 Correct 1 ms 620 KB Output is correct
9 Correct 3 ms 620 KB Output is correct
10 Correct 3 ms 620 KB Output is correct
11 Correct 3 ms 620 KB Output is correct
12 Correct 3 ms 620 KB Output is correct
13 Correct 3 ms 620 KB Output is correct
14 Correct 37 ms 620 KB Output is correct
15 Correct 36 ms 748 KB Output is correct
16 Correct 41 ms 620 KB Output is correct
17 Correct 41 ms 628 KB Output is correct
18 Correct 40 ms 620 KB Output is correct
19 Correct 30 ms 620 KB Output is correct
20 Correct 6 ms 748 KB Output is correct
21 Correct 7 ms 620 KB Output is correct
22 Correct 6 ms 640 KB Output is correct
23 Correct 6 ms 620 KB Output is correct
24 Correct 1 ms 364 KB Output is correct
25 Correct 30 ms 620 KB Output is correct
26 Correct 36 ms 620 KB Output is correct
27 Correct 23 ms 748 KB Output is correct
28 Correct 35 ms 620 KB Output is correct
29 Correct 34 ms 620 KB Output is correct
30 Correct 41 ms 620 KB Output is correct