This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
void ckmin(int& a, int b){
a = min(a, b);
}
void ckmax(int& a, int b){
a = max(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];
int dp[305*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);
}
for(int i = 1; i < 305*305; i++){
dp[i] = -MOD;
}
for(int i = 0; i < M; i++){
for(int j = 305*305-1; j >= B[i]; j--){
ckmax(dp[j], dp[j-B[i]]+Bp[i]);
}
// for(int j = 0; j <= 12; j++){
// cout << dp[j] << " ";
// }
// cout << "\n";
}
for(int i = Asum; i < 305*305; i++){
if(dp[i] >= N*K){
cout << i-Asum << "\n";
exit(0);
}
}
cout << "Impossible" << "\n";
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |