답안 #878939

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
878939 2023-11-25T16:19:29 Z Tien_Noob Kitchen (BOI19_kitchen) C++17
100 / 100
20 ms 816 KB
//Make CSP great again
//Vengeance
#include <bits/stdc++.h>
#define TASK "TESTCODE"
using namespace std;
const int N = 3e2;
int dp[N * N + 1];
int n, m, k, a[N + 1], b[N + 1], sum;
void read()
{
    cin >> n >> m >> k;
    for (int i = 1; i <= n; ++ i)
    {
        cin >> a[i];
        if (a[i] < k)
        {
            cout << "Impossible";
            exit(0);
        }
        sum += a[i];
    }
    for (int j = 1; j <= m; ++ j)
    {
        cin >> b[j];
    }
}
void solve()
{
    memset(dp, -0x3f, sizeof(dp));
    dp[0] = 0;
    for (int j = 1; j <= m; ++ j)
    {
        for (int i = N * N - b[j]; i >= 0; -- i)
        {
            dp[i + b[j]] = max(dp[i + b[j]], dp[i] + min(n, b[j]));
        }
    }
    for (int i = sum; i <= N * N; ++ i)
    {
        if (dp[i] >= n * k)
        {
            cout << i - sum;
            return ;
        }
    }
    cout << "Impossible";
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    if (fopen(TASK".INP", "r"))
    {
        freopen(TASK".INP", "r", stdin);
        //freopen(TASK".OUT", "w", stdout);
    }
    int t = 1;
    bool typetest = false;
    if (typetest)
    {
        cin >> t;
    }
    for (int __ = 1; __ <= t; ++ __)
    {
        //cout << "Case " << __ << ": ";
        read();
        solve();
    }
}

Compilation message

kitchen.cpp: In function 'int main()':
kitchen.cpp:54:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   54 |         freopen(TASK".INP", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
# 결과 실행 시간 메모리 Grader output
1 Correct 1 ms 604 KB Output is correct
2 Correct 1 ms 604 KB Output is correct
3 Correct 1 ms 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 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 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 720 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 17 ms 604 KB Output is correct
2 Correct 15 ms 604 KB Output is correct
3 Correct 20 ms 604 KB Output is correct
4 Correct 20 ms 604 KB Output is correct
5 Correct 19 ms 604 KB Output is correct
6 Correct 14 ms 604 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 604 KB Output is correct
2 Correct 3 ms 604 KB Output is correct
3 Correct 3 ms 604 KB Output is correct
4 Correct 3 ms 604 KB Output is correct
5 Correct 0 ms 348 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 604 KB Output is correct
4 Correct 1 ms 604 KB Output is correct
5 Correct 1 ms 604 KB Output is correct
6 Correct 0 ms 348 KB Output is correct
7 Correct 0 ms 348 KB Output is correct
8 Correct 1 ms 604 KB Output is correct
9 Correct 1 ms 604 KB Output is correct
10 Correct 1 ms 720 KB Output is correct
11 Correct 2 ms 604 KB Output is correct
12 Correct 2 ms 604 KB Output is correct
13 Correct 1 ms 604 KB Output is correct
14 Correct 17 ms 604 KB Output is correct
15 Correct 15 ms 604 KB Output is correct
16 Correct 20 ms 604 KB Output is correct
17 Correct 20 ms 604 KB Output is correct
18 Correct 19 ms 604 KB Output is correct
19 Correct 14 ms 604 KB Output is correct
20 Correct 3 ms 604 KB Output is correct
21 Correct 3 ms 604 KB Output is correct
22 Correct 3 ms 604 KB Output is correct
23 Correct 3 ms 604 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 14 ms 604 KB Output is correct
26 Correct 16 ms 604 KB Output is correct
27 Correct 11 ms 604 KB Output is correct
28 Correct 16 ms 816 KB Output is correct
29 Correct 17 ms 600 KB Output is correct
30 Correct 20 ms 604 KB Output is correct