Submission #1005339

# Submission time Handle Problem Language Result Execution time Memory
1005339 2024-06-22T10:36:30 Z rahidilbayramli Kitchen (BOI19_kitchen) C++17
100 / 100
19 ms 1112 KB
#pragma GCC optimize("-O3")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define vl vector<ll>
#define vi vector<int>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define pb push_back
#define p_b pop_back
#define f first
#define s second
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const ll sz = 9e4+5;
ll dp[sz];
void solve()
{
    ll n, m, k, sum = 0, sumb = 0, i, j;
    cin >> n >> m >> k;
    ll a[n+5], b[m+5];
    for(i = 1; i <= n; i++){
        cin >> a[i];
        sum += a[i];
    }
    for(i = 1; i <= m; i++)
        cin >> b[i];
    sort(a+1, a+n+1);
    sort(b+1, b+m+1);
    if(m < k || a[1] < k)
        cout << "Impossible\n";
    else{
        for(i = 1; i <= m; i++)
        {
            for(j = sz; j >= b[i]; j--)
            {
                if(j == b[i] || dp[j - b[i]])
                    dp[j] = max(dp[j], dp[j-b[i]] + min(b[i], n));
            }
        }
        bool ok = false;
        for(i = sum; i <= sz; i++)
        {
            if(dp[i] >= n * k && !ok)
            {
                cout << i - sum << "\n";
                ok = true;
            }
        }
        if(!ok)
        cout << "Impossible\n";
    }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll tests = 1;
    //cin >> tests;
    while(tests--)
    {
        solve();
    }
}

Compilation message

kitchen.cpp: In function 'void solve()':
kitchen.cpp:24:26: warning: unused variable 'sumb' [-Wunused-variable]
   24 |     ll n, m, k, sum = 0, sumb = 0, i, j;
      |                          ^~~~
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 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 1 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 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 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 2 ms 344 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 17 ms 856 KB Output is correct
2 Correct 17 ms 800 KB Output is correct
3 Correct 18 ms 604 KB Output is correct
4 Correct 18 ms 1108 KB Output is correct
5 Correct 19 ms 1112 KB Output is correct
6 Correct 12 ms 600 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 5 ms 348 KB Output is correct
2 Correct 5 ms 348 KB Output is correct
3 Correct 3 ms 344 KB Output is correct
4 Correct 3 ms 348 KB Output is correct
5 Correct 0 ms 348 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Correct 0 ms 348 KB Output is correct
4 Correct 1 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 1 ms 348 KB Output is correct
9 Correct 1 ms 348 KB Output is correct
10 Correct 1 ms 348 KB Output is correct
11 Correct 1 ms 348 KB Output is correct
12 Correct 2 ms 348 KB Output is correct
13 Correct 2 ms 344 KB Output is correct
14 Correct 17 ms 856 KB Output is correct
15 Correct 17 ms 800 KB Output is correct
16 Correct 18 ms 604 KB Output is correct
17 Correct 18 ms 1108 KB Output is correct
18 Correct 19 ms 1112 KB Output is correct
19 Correct 12 ms 600 KB Output is correct
20 Correct 5 ms 348 KB Output is correct
21 Correct 5 ms 348 KB Output is correct
22 Correct 3 ms 344 KB Output is correct
23 Correct 3 ms 348 KB Output is correct
24 Correct 0 ms 348 KB Output is correct
25 Correct 13 ms 744 KB Output is correct
26 Correct 16 ms 860 KB Output is correct
27 Correct 10 ms 672 KB Output is correct
28 Correct 15 ms 860 KB Output is correct
29 Correct 16 ms 860 KB Output is correct
30 Correct 19 ms 856 KB Output is correct