Submission #1122990

#TimeUsernameProblemLanguageResultExecution timeMemory
1122990hqminhuwuKitchen (BOI19_kitchen)C++17
0 / 100
143 ms215332 KiB
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector <int> vi;
typedef pair <ll,ll> pll;
typedef pair <int,int> pii;
typedef pair <int,pii> piii;

#define forr(_a,_b,_c) for(int _a = (_b); _a <= int (_c); ++_a)
#define ford(_a,_b,_c) for(int _a = (_b) + 1; _a --> int (_c);)
#define forf(_a,_b,_c) for(int _a = (_b); _a < int (_c); ++_a)
#define st first
#define nd second
#define pb push_back
#define mp make_pair
#define all(x) begin(x),end(x)
#define mask(i) (1LL << (i))
#define bit(x, i) (((x) >> (i)) & 1)
#define bp __builtin_popcountll
#define file "test"

template<class X, class Y>
    bool minz(X &x, const Y &y) {
        if (x > y) {
            x = y;
            return true;
        } return false;
    }
template<class X, class Y>
    bool maxz(X &x, const Y &y) {
        if (x < y) {
            x = y;
            return true;
        } return false;
    }

const int N = 3e2 + 5;
const ll oo = (ll) 1e16;
const ll mod = 1e9 + 7; // 998244353;
const int lmt = 300 * 300;


int n, m, k, a[N], b[N], dp[N][2 * lmt + 2];

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifndef ONLINE_JUDGE
        freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout);
    #endif

    cin >> n >> m >> k;

    int sum = 0;

    forr (i, 1, n){
        cin >> a[i];
        sum += a[i];
    }
    sum -= n * k;

    forr (i, 1, m){
        cin >> b[i];
    }


    sort(a + 1, a + 1 + n);

    if (a[1] < k){
        cout << "Impossible\n";
        return 0;
    }

    memset (dp, -63, sizeof dp);

    dp[0][0] = 0;

    forr (i, 1, m){
        forr (j, 0, lmt){
            if (dp[i - 1][j] < 0) continue;
            int uwu = min(n * k - dp[i - 1][j], min(b[i], n));
            maxz(dp[i][j + b[i] - uwu], dp[i - 1][j] + uwu);
            maxz(dp[i][j], dp[i - 1][j]);
        }
    }


    forr (i, sum, lmt){
        if (dp[m][i] == n * k){
            cout << i - sum << "\n";
            return 0;
        }
    }

    cout << "Impossible\n";

    return 0;
}
/*



*/

Compilation message (stderr)

kitchen.cpp: In function 'int main()':
kitchen.cpp:49:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |         freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~
kitchen.cpp:49:49: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   49 |         freopen(file".inp", "r", stdin); freopen(file".out", "w", stdout);
      |                                          ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...