Submission #1004271

# Submission time Handle Problem Language Result Execution time Memory
1004271 2024-06-21T07:04:17 Z vjudge1 Kitchen (BOI19_kitchen) C++17
0 / 100
0 ms 348 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;
void solve()
{
    ll n, m, k, i, j;
    cin >> n >> m >> k;
    ll a[n+5], b[m+5];
    for(i = 1; i <= n; i++)
        cin >> a[i];
    for(j = 1; j <= m; j++)
        cin >> b[j];
    if(k > m)
    {
        cout << "Impossible\n";
        return;
    }
    bool ok = true;
    for(i = 1; i <= n; i++)
    {
        if(a[i] < k)
        {
            ok = false;
            break;
        }
    }
    if(!ok)
    {
        cout << "Impossible\n";
        return;
    }
    deque<ll>dq;
    for(i = 1; i <= m; i++)
        dq.pb(b[i]);
    sort(all(dq));
    sort(a+1, a+n+1);
    ok = true;
    for(i = n; i >= 1; i--)
    {
        ll h = k - 1;
        for(j = 0; j < m; j++)
        {
            if(dq[j] && h)
            {
                h--;
                dq[j]--;
                a[i]--;
            }
        }
        for(j = m - 1; j >= 0; j--)
        {
            if(a[i])
            {
                ll c = min(a[i], dq[j]);
                dq[j] -= c;
                a[i] -= c;
            }
        }
        if(h || a[i])
        {
            ok = false;
            break;
        }
    }
    if(!ok)
        cout << "Impossible\n";
    else
    {
        ll res = 0;
        for(i = 0; i < m; i++)
            res += dq[i];
        cout << res << "\n";
    }
}
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll tests = 1;
    //cin >> tests;
    while(tests--)
    {
        solve();
    }
}
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -