답안 #688491

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
688491 2023-01-27T14:17:07 Z stanislavpolyn Kitchen (BOI19_kitchen) C++17
100 / 100
21 ms 724 KB
#include <bits/stdc++.h>

#define fr(i, a, b) for (int i = (a); i <= (b); ++i)
#define rf(i, a, b) for (int i = (a); i >= (b); --i)
#define fe(x, y) for (auto& x : y)

#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define mt make_tuple

#define all(x) (x).begin(), (x).end()
#define pw(x) (1LL << (x))
#define sz(x) (int)(x).size()

using namespace std;

mt19937_64 rng(228);

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define fbo find_by_order
#define ook order_of_key

template <typename T>
bool umn(T& a, T b) {
    return a > b ? a = b, 1 : 0;
}
template <typename T>
bool umx(T& a, T b) {
    return a < b ? a = b, 1 : 0;
}

using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename T>
using ve = vector<T>;

const int N = 305;
const int M = 305 * 305;

int n, m, k, sumA;
int a[N], b[N];


int dp[M];
//int ndp[M];

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#else
    ios::sync_with_stdio(0);
    cin.tie(0);
#endif

    cin >> n >> m >> k;

    fr (i, 1, n) {
        cin >> a[i];

        if (a[i] < k) {
            cout << "Impossible\n";
            return 0;
        }
        sumA += a[i];
    }
    fr (i, 1, m) {
        cin >> b[i];
    }

    {
        fr (i, 0, M - 1) {
            dp[i] = -1e9;
        }

        dp[0] = 0;
        fr (i, 1, m) {
            rf (sum, M - 1, b[i]) {
                umx(dp[sum], dp[sum - b[i]] + min(b[i], n));
            }
        }

        fr (i, sumA, M - 1) {
            if (dp[i] >= n * k) {
                cout << i - sumA << "\n";
                return 0;
            }
        }

        cout << "Impossible\n";
    }

//    int best = 2e9;
//    fr (mask, 0, pw(m) - 1) {
//        int sum = 0;
//        int sum2 = 0;
//        fr (i, 1, m) {
//            if (mask & pw(i - 1)) {
//                sum += b[i];
//                sum2 += min(n, b[i]);
//            }
//        }
//
//        if (sum >= sumA && sum2 >= n * k) {
//            umn(best, sum - sumA);
//        }
//    }
//
//    if (best == 2e9) {
//        cout << "Impossible\n";
//    } else {
//        cout << best << "\n";
//    }

    return 0;
}
# 결과 실행 시간 메모리 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 1 ms 596 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
# 결과 실행 시간 메모리 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 1 ms 596 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 2 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 16 ms 724 KB Output is correct
2 Correct 14 ms 596 KB Output is correct
3 Correct 19 ms 596 KB Output is correct
4 Correct 20 ms 584 KB Output is correct
5 Correct 18 ms 596 KB Output is correct
6 Correct 13 ms 692 KB Output is correct
# 결과 실행 시간 메모리 Grader output
1 Correct 3 ms 596 KB Output is correct
2 Correct 4 ms 596 KB Output is correct
3 Correct 3 ms 596 KB Output is correct
4 Correct 3 ms 596 KB Output is correct
5 Correct 1 ms 212 KB Output is correct
# 결과 실행 시간 메모리 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 1 ms 596 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 2 ms 596 KB Output is correct
10 Correct 2 ms 596 KB Output is correct
11 Correct 1 ms 596 KB Output is correct
12 Correct 1 ms 596 KB Output is correct
13 Correct 1 ms 596 KB Output is correct
14 Correct 16 ms 724 KB Output is correct
15 Correct 14 ms 596 KB Output is correct
16 Correct 19 ms 596 KB Output is correct
17 Correct 20 ms 584 KB Output is correct
18 Correct 18 ms 596 KB Output is correct
19 Correct 13 ms 692 KB Output is correct
20 Correct 3 ms 596 KB Output is correct
21 Correct 4 ms 596 KB Output is correct
22 Correct 3 ms 596 KB Output is correct
23 Correct 3 ms 596 KB Output is correct
24 Correct 1 ms 212 KB Output is correct
25 Correct 14 ms 596 KB Output is correct
26 Correct 16 ms 596 KB Output is correct
27 Correct 11 ms 596 KB Output is correct
28 Correct 16 ms 596 KB Output is correct
29 Correct 18 ms 696 KB Output is correct
30 Correct 21 ms 704 KB Output is correct