Submission #915769

# Submission time Handle Problem Language Result Execution time Memory
915769 2024-01-24T16:44:43 Z RaulAndrei01 Kitchen (BOI19_kitchen) C++14
100 / 100
28 ms 768 KB
#include<iostream>
#include<vector>
 
using namespace std;
const int NMAX = 400;
const int INF = 1e7;
int a[NMAX+1] , b[NMAX+1];
 
int dp[NMAX*NMAX+1]; // dp[sum] = cate ore max sunt eligibile pt n*k
 
int main ()
{
    int n, m, k;
    cin >> n >> m >> k;
 
    int sumA = 0;
    bool bad = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        sumA += a[i];
        if (a[i] < k) bad = 1;
    }
    
    int sumB = 0;
    for (int i = 1; i <= m; i++)
    {
        cin >> b[i];
        sumB += b[i];
    }
 
    if (bad || sumB < sumA) {
        cout << "Impossible\n";
        return 0;
    }
 
    for (int i = 0; i <= sumB; i++)
    {
        dp[i] = -INF;
    }
    
    dp[0] = 0;
 
    for (int i = 1; i <= m; i++)
    {
        for (int sum = sumB; sum >= b[i]; sum--)
        {
            int addToNK = min(b[i] , n);
            dp[sum] = max(dp[sum] , dp[sum-b[i]] + addToNK);
            
        }
    }
 
    int ans = 0;
    for (int i = sumA; i <= sumB; i++)
    {
        
        if (dp[i] >= n*k)
        {
            cout << i - sumA << '\n';
            return 0;
        }
    }
    
    cout << "Impossible\n";
}

Compilation message

kitchen.cpp: In function 'int main()':
kitchen.cpp:54:9: warning: unused variable 'ans' [-Wunused-variable]
   54 |     int ans = 0;
      |         ^~~
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 352 KB Output is correct
8 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 352 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 348 KB Output is correct
13 Correct 1 ms 444 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 13 ms 704 KB Output is correct
2 Correct 10 ms 604 KB Output is correct
3 Correct 11 ms 604 KB Output is correct
4 Correct 19 ms 768 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
6 Correct 8 ms 604 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 1 ms 348 KB Output is correct
4 Correct 0 ms 348 KB Output is correct
5 Correct 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 344 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 352 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 348 KB Output is correct
13 Correct 1 ms 444 KB Output is correct
14 Correct 13 ms 704 KB Output is correct
15 Correct 10 ms 604 KB Output is correct
16 Correct 11 ms 604 KB Output is correct
17 Correct 19 ms 768 KB Output is correct
18 Correct 0 ms 348 KB Output is correct
19 Correct 8 ms 604 KB Output is correct
20 Correct 1 ms 348 KB Output is correct
21 Correct 0 ms 348 KB Output is correct
22 Correct 1 ms 348 KB Output is correct
23 Correct 0 ms 348 KB Output is correct
24 Correct 1 ms 348 KB Output is correct
25 Correct 9 ms 604 KB Output is correct
26 Correct 12 ms 604 KB Output is correct
27 Correct 4 ms 344 KB Output is correct
28 Correct 10 ms 652 KB Output is correct
29 Correct 13 ms 604 KB Output is correct
30 Correct 28 ms 604 KB Output is correct