Submission #758754

# Submission time Handle Problem Language Result Execution time Memory
758754 2023-06-15T08:52:14 Z Hanksburger Kitchen (BOI19_kitchen) C++17
51 / 100
36 ms 680 KB
#include <bits/stdc++.h>
using namespace std;
int a[305], B[305], b[305], dp[90005];
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, M, k, x1=0, ans=1e9;
    cin >> n >> M >> k;
    if (k==1)
    {
        int sum=0;
        for (int i=1; i<=n; i++)
        {
            cin >> a[i];
            sum+=a[i];
        }
        dp[0]=1;
        for (int i=1; i<=M; i++)
        {
            cin >> b[i];
            for (int j=90000; j>=b[i]; j--)
                dp[j]+=dp[j-b[i]];
        }
        for (int i=sum; i<=90000; i++)
        {
            if (dp[i])
            {
                cout << i-sum;
                return 0;
            }
        }
        cout << "Impossible";
        return 0;
    }
    for (int i=1; i<=n; i++)
    {
        cin >> a[i];
        x1+=a[i];
    }
    for (int i=1; i<=M; i++)
        cin >> B[i];
    for (int z=1; z<(1<<M); z++)
    {
        int m=0, x2=0;
        for (int zz=0; zz<M; zz++)
        {
            if (z&(1<<zz))
            {
                m++;
                b[m]=B[zz+1];
                x2+=b[m];
            }
        }
        bool ok=1;
        if (m<k || x1>x2)
        {
            ok=0;
            continue;
        }
        sort(b+1, b+m+1);
        for (int i=1; i<=n; i++)
        {
//            cout << "a[i]=" << a[i] << ' ';
            if (a[i]<k)
            {
                ok=0;
                break;
            }
            for (int j=m-k+1; j<=m; j++)
            {
                b[j]--;
//                cout << "subtract " << b[j] << ' ';
                if (b[j]<0)
                {
                    ok=0;
//                    cout << "out\n";
                    break;
                }
            }
            if (!ok)
                break;
            sort(b+1, b+m+1);
            int l=0, r=300;
            while (l<r)
            {
                int mid=(l+r)/2, sum=0;
                for (int j=m; j>=1; j--)
                {
                    if (b[j]<mid)
                        break;
                    sum+=b[j]-mid;
                }
                if (sum<=a[i]-k)
                    r=mid;
                else
                    l=mid+1;
            }
//            cout << "l=" << l << ' ';
            int sum=0;
            for (int j=m; j>=1; j--)
            {
                if (b[j]<l)
                    break;
                sum+=b[j]-l;
//                cout << "subtract " << b[j]-l << ' ';
                b[j]=l;
            }
            sort(b+1, b+m+1);
            for (int j=m; j>=m-(a[i]-k-sum)+1; j--)
            {
                b[j]--;
//                cout << "subtract " << b[j] << ' ';
            }
            sort(b+1, b+m+1);
//            cout << "i=" << i << " over\n";
        }
        if (ok)
            ans=min(ans, x2-x1);
    }
    if (ans==1e9)
        cout << "Impossible";
    else
        cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 10 ms 328 KB Output is correct
10 Correct 16 ms 328 KB Output is correct
11 Correct 3 ms 212 KB Output is correct
12 Correct 2 ms 212 KB Output is correct
13 Correct 36 ms 212 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 15 ms 596 KB Output is correct
2 Correct 13 ms 680 KB Output is correct
3 Correct 17 ms 676 KB Output is correct
4 Correct 17 ms 680 KB Output is correct
5 Correct 20 ms 676 KB Output is correct
6 Correct 12 ms 680 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 596 KB Output is correct
2 Correct 1 ms 596 KB Output is correct
3 Correct 1 ms 596 KB Output is correct
4 Correct 0 ms 212 KB Output is correct
5 Correct 1 ms 596 KB Output is correct
6 Correct 0 ms 212 KB Output is correct
7 Correct 0 ms 212 KB Output is correct
8 Correct 1 ms 596 KB Output is correct
9 Correct 10 ms 328 KB Output is correct
10 Correct 16 ms 328 KB Output is correct
11 Correct 3 ms 212 KB Output is correct
12 Correct 2 ms 212 KB Output is correct
13 Correct 36 ms 212 KB Output is correct
14 Correct 15 ms 596 KB Output is correct
15 Correct 13 ms 680 KB Output is correct
16 Correct 17 ms 676 KB Output is correct
17 Correct 17 ms 680 KB Output is correct
18 Correct 20 ms 676 KB Output is correct
19 Correct 12 ms 680 KB Output is correct
20 Incorrect 0 ms 212 KB Output isn't correct
21 Halted 0 ms 0 KB -