#include <bits/stdc++.h>
#define PB push_back
#define ST first
#define ND second
#define _ ios_base::sync_with_stdio(0); cin.tie(0);
//mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
using namespace std;
using ll = long long;
using pi = pair<int,int>;
using vi = vector<int>;
const int nax = 300 + 1, INF = 1e9;
int n,m,k;
int s,s2;
int t[nax];
int dp[nax * nax][nax];
int main() {_
cin >> n >> m >> k;
bool ok = 1;
for(int a,i = 1; i <= n; ++i) {
cin >> a;
if(a < k) ok = 0;
s += a;
}
for(int i = 1; i <= m; ++i) {
cin >> t[i];
s2 += t[i];
}
if(!ok) {
cout << "Impossible";
return 0;
}
for(int i = 0; i <= s2; ++i) {
dp[i][0] = -INF;
}
dp[0][0] = 0;
for(int i = 1; i <= m; ++i) {
for(int j = 0; j <= s2; ++j) {
dp[j][i] = max(dp[j][i-1], (j >= t[i] ? (dp[j - t[i]][i-1] + min(t[i], n)) : 0));
}
}
int ans = INF;
for(int i = s; i <= s2; ++i) {
if(dp[i][m] >= k * n) {
ans = i;
break;
}
}
if(ans == INF) cout << "Impossible";
else {
cout << ans - s;
}
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
640 KB |
Output is correct |
2 |
Correct |
5 ms |
640 KB |
Output is correct |
3 |
Incorrect |
5 ms |
768 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
640 KB |
Output is correct |
2 |
Correct |
5 ms |
640 KB |
Output is correct |
3 |
Incorrect |
5 ms |
768 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
204 ms |
78200 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
1920 KB |
Output is correct |
2 |
Correct |
5 ms |
1408 KB |
Output is correct |
3 |
Correct |
5 ms |
1792 KB |
Output is correct |
4 |
Correct |
6 ms |
2048 KB |
Output is correct |
5 |
Correct |
4 ms |
384 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
5 ms |
640 KB |
Output is correct |
2 |
Correct |
5 ms |
640 KB |
Output is correct |
3 |
Incorrect |
5 ms |
768 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |