답안 #566947

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
566947 2022-05-23T06:44:32 Z shrimb Kitchen (BOI19_kitchen) C++17
0 / 100
1 ms 468 KB
#pragma GCC optimize ("Ofast")
#pragma GCC target ("avx,avx2,fma")

#include"bits/stdc++.h"
using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template<class x>
using ordered_set = tree<x, null_type,less<x>, rb_tree_tag,tree_order_statistics_node_update>;

#define int long long
#define endl '\n'
#define mod 1000000007
//\
#define mod 1686876991

const int maxn = 301;

int n, m, k, cntAK, cntBK, smA, smB, ans = 1e9;

int A[maxn], B[maxn];

signed main () {
    cin.tie(0)->sync_with_stdio(0);
    cin >> n >> m >> k;
    for (int i = 0 ; i < n ; i++) {
        cin >> A[i];
        smA += A[i];
        if (A[i] < k) cntAK++;
    }
    for (int i = 0 ; i < m ; i++) {
        cin >> B[i];
        if (B[i] >= k) cntBK++;
        smB += B[i];
    }
    if (m < k || smB < smA || cntBK < n || cntAK) {
        assert(0);
        cout << "Impossible\n";
        return 0;
    }
    if (m <= 15) { // subtasks 1 and 2
        for (int i = 0 ; i < (1 << m) ; i++) {
            smB = 0, cntBK = 0;
            if (__builtin_popcount(i) < k) continue;
            for (int j = 0 ; j < m ; j++) {
                if (i & (1 << j)) {
                    smB += B[j];
                    if (B[j] >= k) cntBK++;
                }
            }
            if (smB >= smA and cntBK >= n) ans = min(ans, smB - smA);
        }
        cout << ans << endl;
        return 0;
    }
}


/*

impossible:

- M < K
- sum of B < sum of A
- the number of (B >= K) is < N
- theres an A which is < K

*/

Compilation message

kitchen.cpp:17:1: warning: multi-line comment [-Wcomment]
   17 | //\
      | ^
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 0 ms 212 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Runtime error 1 ms 468 KB Execution killed with signal 6
2 Halted 0 ms 0 KB -