#include <bits/stdc++.h>
#define F first
#define S second
#define int long long
using namespace std;
const int maxn = 3e2 + 3, inf = 1e9 + 9;
int n, m, k, ans = inf, sum;
int a[maxn], b[maxn], dp[maxn][maxn * maxn];
bool check;
void read_input() {
cin >> n >> m >> k;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum += a[i];
check |= (a[i] < k);
}
for (int i = 1; i <= m; i++)
cin >> b[i];
}
void solve() {
memset(dp, -1, sizeof dp);
dp[0][0] = 0;
for (int i = 1; i <= m; i++)
for (int j = 0; j < maxn * maxn; j++) {
dp[i][j] = dp[i - 1][j];
if (j - b[i] >= 0)
dp[i][j] = max(dp[i][j], dp[i - 1][j - b[i]] + min(n, b[i]));
if (j >= sum && dp[i][j] >= n * k)
ans = min(ans, j - sum);
}
if (ans > maxn * maxn || check)
cout << "Impossible";
else
cout << ans;
}
int32_t main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
read_input(), solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
218052 KB |
Output is correct |
2 |
Correct |
88 ms |
217996 KB |
Output is correct |
3 |
Correct |
76 ms |
217932 KB |
Output is correct |
4 |
Correct |
84 ms |
217968 KB |
Output is correct |
5 |
Correct |
78 ms |
218052 KB |
Output is correct |
6 |
Correct |
76 ms |
217972 KB |
Output is correct |
7 |
Correct |
86 ms |
217956 KB |
Output is correct |
8 |
Incorrect |
79 ms |
218052 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
218052 KB |
Output is correct |
2 |
Correct |
88 ms |
217996 KB |
Output is correct |
3 |
Correct |
76 ms |
217932 KB |
Output is correct |
4 |
Correct |
84 ms |
217968 KB |
Output is correct |
5 |
Correct |
78 ms |
218052 KB |
Output is correct |
6 |
Correct |
76 ms |
217972 KB |
Output is correct |
7 |
Correct |
86 ms |
217956 KB |
Output is correct |
8 |
Incorrect |
79 ms |
218052 KB |
Output isn't correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
138 ms |
218020 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
83 ms |
218044 KB |
Output is correct |
2 |
Correct |
81 ms |
218052 KB |
Output is correct |
3 |
Correct |
91 ms |
218052 KB |
Output is correct |
4 |
Correct |
88 ms |
218056 KB |
Output is correct |
5 |
Correct |
84 ms |
217992 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
85 ms |
218052 KB |
Output is correct |
2 |
Correct |
88 ms |
217996 KB |
Output is correct |
3 |
Correct |
76 ms |
217932 KB |
Output is correct |
4 |
Correct |
84 ms |
217968 KB |
Output is correct |
5 |
Correct |
78 ms |
218052 KB |
Output is correct |
6 |
Correct |
76 ms |
217972 KB |
Output is correct |
7 |
Correct |
86 ms |
217956 KB |
Output is correct |
8 |
Incorrect |
79 ms |
218052 KB |
Output isn't correct |