Submission #385298

#TimeUsernameProblemLanguageResultExecution timeMemory
385298rqiKitchen (BOI19_kitchen)C++14
31 / 100
5 ms748 KiB
#include <bits/stdc++.h> using namespace std; void ckmin(int& a, int b){ a = min(a, b); } const int MOD = 1e9+7; const int mx = 305; int N, M, K; int Asum = 0; int A[mx]; int B[mx]; int Bp[mx]; bitset<305*305> dp1; bitset<305*305> dp[305]; int main(){ cin >> N >> M >> K; for(int i = 0; i < N; i++){ cin >> A[i]; Asum+=A[i]; } for(int i = 0; i < M; i++){ cin >> B[i]; } for(int i = 0; i < N; i++){ if(A[i] < K){ cout << "Impossible" << "\n"; exit(0); } } for(int i = 0; i < M; i++){ Bp[i] = min(B[i], N); } if(M <= 15){ int ans = MOD; for(int i = 0; i < (1<<M); i++){ int Bsum = 0; int Bpsum = 0; for(int j = 0; j < M; j++){ if((i>>j)&1){ Bsum+=B[j]; Bpsum+=Bp[j]; } } if(Bsum >= Asum && Bpsum >= N*K){ ckmin(ans, Bsum); } } if(ans == MOD){ cout << "Impossible" << "\n"; } else{ cout << ans-Asum << "\n"; } exit(0); } dp1[0] = 1; for(int i = 0; i < M; i++){ if(B[i] <= N){ dp1|=(dp1<<B[i]); } } for(int i = 0; i < 305*305; i++){ if(dp1[i] == 1) dp[min(i/N, K)][i] = 1; } for(int i = 0; i < M; i++){ if(B[i] <= N) continue; for(int j = 1; j <= K+1; j++){ if(j == K+1){ dp[K]|=(dp[K]<<B[i]); } else{ dp[j]|=(dp[j-1]<<B[i]); } } } for(int i = Asum; i < 305*305; i++){ if(dp[K][i] == 1){ cout << i << "\n"; exit(0); } } cout << "Impossible" << "\n"; }
#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...