제출 #697942

#제출 시각아이디문제언어결과실행 시간메모리
697942jiahngKitchen (BOI19_kitchen)C++14
100 / 100
234 ms199320 KiB
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
#define int ll
typedef pair<int, int> pi;
typedef vector <int> vi;
typedef vector <pi> vpi;
typedef pair <pi,pi> pipi;
typedef pair<pi, ll> pii;
typedef set <ll> si;
typedef long double ld;
#define f first
#define s second
#define mp make_pair
#define FOR(i,s,e) for(int i=s;i<=int(e);++i)
#define DEC(i,s,e) for(int i=s;i>=int(e);--i)
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define lbd(x, y) lower_bound(all(x), y)
#define ubd(x, y) upper_bound(all(x), y)
#define aFOR(i,x) for (auto i: x)
#define mem(x,i) memset(x,i,sizeof x)
#define fast ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define maxn 310
#define INF (ll)1e18
#define MOD 998244353
typedef pair <vi, int> pvi;
typedef pair <int,pi> ipi;
typedef vector <pii> vpii;
#define DEBUG 0
#pragma GCC optimize("trapv")
int N,M,K,A[maxn],B[maxn];
int dp[maxn][maxn*maxn];

int32_t main(){
    cin >> N >> M >> K;
    FOR(i,1,N) cin >> A[i];
    FOR(i,1,M) cin >> B[i];
    int sumA = accumulate(A+1,A+N+1,0);
    int sumB = accumulate(B+1,B+M+1,0);

    if (sumA > sumB){
        cout << "Impossible"; return 0;
    }

    FOR(i,1,N){
        if (A[i] < K){
            cout << "Impossible"; return 0;
        }
    }
    dp[M+1][0] = 0;
    FOR(j,1,sumB) dp[M+1][j] = -INF;
    DEC(i,M,1){
        FOR(j,0,sumB){
            if (j >= B[i]) dp[i][j] = max(dp[i+1][j], dp[i+1][j-B[i]] + min(B[i], N));
            else dp[i][j] = dp[i+1][j];
        }
    }
    FOR(j,sumA,sumB) if (dp[1][j] >= K*N){
        cout << j - sumA; return 0;
    }
    cout << "Impossible";
}
#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...