이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MAX_S = 305 * 305;
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int N, M, K;
cin >> N >> M >> K;
vector<int> A(N), B(M);
for (int &v : A) {
cin >> v;
if (v < K) {
cout << "Impossible\n";
exit(0);
}
}
for (int &v : B) {
cin >> v;
}
int SA = accumulate(A.begin(), A.end(), 0);
bitset<MAX_S> bs;
vector<int> dp(MAX_S, -1e9);
dp[0] = 0;
bs[0] = 1;
for (int i = 0; i < M; i++) {
if (B[i] < N) {
bs |= bs << B[i];
} else {
vector<int> new_dp = dp;
for (int j = 0; j + B[i] < MAX_S; j++) {
new_dp[j + B[i]] = max(new_dp[j + B[i]], dp[j] + 1);
}
dp = new_dp;
}
}
vector<int> reachable;
for (int i = 0; i < MAX_S; i++) {
if (bs[i]) {
reachable.push_back(i);
}
}
int ans = INT_MAX;
for (int j = 0; j < MAX_S; j++) {
if (dp[j] >= 0) {
auto it = lower_bound(reachable.begin(), reachable.end(), max(N * (K - dp[j]), SA - j));
if (it != reachable.end()) {
ans = min(ans, *it + j - SA);
}
}
}
if (ans == INT_MAX) {
cout << "Impossible\n";
} else {
cout << ans << "\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... |