이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include<iostream>
#include<algorithm>
#include<cstring>
using namespace std;
int n, m, k;
const int maxn = 310;
const int inf = maxn * maxn + 400;
int a[maxn];
int az = 0;
int b[maxn];
int dp[maxn][inf];
int sol = inf;
int main(){
//memset(dp, -inf, sizeof(dp));
ios_base::sync_with_stdio(false);
cin.tie(0);
cin >> n >> m >> k;
int r = 0;
for (int i = 0; i < n; i++){
cin >> a[i];
az += a[i];
if (a[i] < k){
r = 1;
}
}
for (int i = 0; i < m; i++){
cin >> b[i];
}
for (int i = 0; i <= m; i++){
for (int j = 0; j < maxn * maxn; j++){
dp[i][j] = -inf;
}
}
dp[m][0] = 0;
for (int i = m - 1; i >= 0; i--){
for (int j = maxn * maxn; j >= 0; j--){
//dp[i][j] = dp[i + 1][j - b[i]] + min(n, b[i]);
dp[i][j] = dp[i + 1][j];
dp[i][j + b[i]] = max(dp[i][j + b[i]], dp[i + 1][j] + min(n, b[i]));
}
}
//cout << az << endl;
for (int j = maxn * maxn; j >= 0; j--){
if (dp[0][j] >= k * n && j >= az){
sol = min(sol, j);
}
}
if (r == 0 && sol != inf){
cout << sol - az;
}
else {
cout << "Impossible";
}
}
# | 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... |