#include <bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
int n, m; cin >> n >> m;
vector<int> a(n), b(m);
for(int i = 0; i < n; ++i){
cin >> a[i];
}
for(int i = 0; i < m; ++i){
cin >> b[i];
}
vector<vector<int>> dp(n, vector<int>(m, (int)1e18));
dp[n - 1][m - 1] = 0;
for(int i = n - 1; i >= 0; --i){
for(int j = m - 1; j >= 0; --j){
if(i + 1 < n){
dp[i][j] = min(dp[i][j], dp[i + 1][j] + b[j]);
}
if(j + 1 < m){
dp[i][j] = min(dp[i][j], dp[i][j + 1] + a[i]);
}
}
}
cout << dp[0][0] << '\n';
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
304 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
300 KB |
Output is correct |
9 |
Correct |
11 ms |
8104 KB |
Output is correct |
10 |
Correct |
11 ms |
8148 KB |
Output is correct |
11 |
Correct |
12 ms |
8148 KB |
Output is correct |
12 |
Correct |
10 ms |
8148 KB |
Output is correct |
13 |
Correct |
11 ms |
8148 KB |
Output is correct |
14 |
Correct |
11 ms |
8148 KB |
Output is correct |
15 |
Correct |
10 ms |
8148 KB |
Output is correct |
16 |
Correct |
10 ms |
8148 KB |
Output is correct |
17 |
Correct |
11 ms |
8148 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
300 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
300 KB |
Output is correct |
25 |
Correct |
0 ms |
304 KB |
Output is correct |
26 |
Correct |
1 ms |
300 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
4 ms |
3284 KB |
Output is correct |
4 |
Runtime error |
517 ms |
1048576 KB |
Execution killed with signal 9 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
212 KB |
Output is correct |
4 |
Correct |
2 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
304 KB |
Output is correct |
6 |
Correct |
1 ms |
340 KB |
Output is correct |
7 |
Correct |
1 ms |
212 KB |
Output is correct |
8 |
Correct |
1 ms |
300 KB |
Output is correct |
9 |
Correct |
11 ms |
8104 KB |
Output is correct |
10 |
Correct |
11 ms |
8148 KB |
Output is correct |
11 |
Correct |
12 ms |
8148 KB |
Output is correct |
12 |
Correct |
10 ms |
8148 KB |
Output is correct |
13 |
Correct |
11 ms |
8148 KB |
Output is correct |
14 |
Correct |
11 ms |
8148 KB |
Output is correct |
15 |
Correct |
10 ms |
8148 KB |
Output is correct |
16 |
Correct |
10 ms |
8148 KB |
Output is correct |
17 |
Correct |
11 ms |
8148 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
212 KB |
Output is correct |
20 |
Correct |
1 ms |
212 KB |
Output is correct |
21 |
Correct |
1 ms |
212 KB |
Output is correct |
22 |
Correct |
1 ms |
300 KB |
Output is correct |
23 |
Correct |
1 ms |
212 KB |
Output is correct |
24 |
Correct |
1 ms |
300 KB |
Output is correct |
25 |
Correct |
0 ms |
304 KB |
Output is correct |
26 |
Correct |
1 ms |
300 KB |
Output is correct |
27 |
Correct |
0 ms |
212 KB |
Output is correct |
28 |
Correct |
1 ms |
212 KB |
Output is correct |
29 |
Correct |
0 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
212 KB |
Output is correct |
31 |
Correct |
4 ms |
3284 KB |
Output is correct |
32 |
Runtime error |
517 ms |
1048576 KB |
Execution killed with signal 9 |
33 |
Halted |
0 ms |
0 KB |
- |