#include <bits/stdc++.h>
#define int long long
using namespace std;
int n, m, k, A, B;
vector<int> a, b;
vector<vector<bool>> dp;
signed main() {
cin >> n >> m >> k;
a = vector<int>(n), b = vector<int>(m);
for(int i = 0; i < n; i++) {
cin >> a[i];
A += a[i];
}
for(int i = 0; i < m; i++) {
cin >> b[i];
B += b[i];
}
//
dp = vector<vector<bool>>(m + 1, vector<bool>(B + 1, false));
dp[0][0] = true;
for(int i = 1; i <= m; i++) {
for(int j = 0; j <= B; j++) {
if(j >= b[i - 1]) dp[i][j] = dp[i - 1][j] | dp[i - 1][j - b[i - 1]];
//cout << dp[i][j] << " ";
}
//cout << "\n";
}
//
int res = LLONG_MAX;
for(int i = 0; i <= m; i++) {
for(int j = A; j <= B; j++) {
if(dp[i][j]) res = min(res, j - A);
}
}
cout << res << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
57 ms |
2548 KB |
Output is correct |
2 |
Correct |
40 ms |
2032 KB |
Output is correct |
3 |
Correct |
45 ms |
2140 KB |
Output is correct |
4 |
Correct |
77 ms |
3420 KB |
Output is correct |
5 |
Incorrect |
71 ms |
3484 KB |
Output isn't correct |
6 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
1 ms |
348 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |