#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAXN = 1000;
const ll inf = 1e18;
ll grid[MAXN][MAXN];
int cost[MAXN][2];
int n, m;
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> cost[i][0];
for (int i = 0; i < m; i++) cin >> cost[i][1];
grid[0][0] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (i+j == 0) continue;
grid[i][j] = inf;
if (i) grid[i][j] = min(grid[i][j], grid[i-1][j]+cost[j][1]);
if (j) grid[i][j] = min(grid[i][j], grid[i][j-1]+cost[i][0]);
}
}
cout << grid[n-1][m-1] << "\n";
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
2256 KB |
Output is correct |
6 |
Correct |
1 ms |
1620 KB |
Output is correct |
7 |
Correct |
1 ms |
1108 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
7 ms |
8144 KB |
Output is correct |
10 |
Correct |
7 ms |
8168 KB |
Output is correct |
11 |
Correct |
8 ms |
8148 KB |
Output is correct |
12 |
Correct |
7 ms |
8148 KB |
Output is correct |
13 |
Correct |
9 ms |
8060 KB |
Output is correct |
14 |
Correct |
7 ms |
8148 KB |
Output is correct |
15 |
Correct |
7 ms |
8148 KB |
Output is correct |
16 |
Correct |
7 ms |
8148 KB |
Output is correct |
17 |
Correct |
9 ms |
8136 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
320 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
328 KB |
Output is correct |
23 |
Correct |
0 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Incorrect |
3 ms |
2644 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
0 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
2256 KB |
Output is correct |
6 |
Correct |
1 ms |
1620 KB |
Output is correct |
7 |
Correct |
1 ms |
1108 KB |
Output is correct |
8 |
Correct |
0 ms |
340 KB |
Output is correct |
9 |
Correct |
7 ms |
8144 KB |
Output is correct |
10 |
Correct |
7 ms |
8168 KB |
Output is correct |
11 |
Correct |
8 ms |
8148 KB |
Output is correct |
12 |
Correct |
7 ms |
8148 KB |
Output is correct |
13 |
Correct |
9 ms |
8060 KB |
Output is correct |
14 |
Correct |
7 ms |
8148 KB |
Output is correct |
15 |
Correct |
7 ms |
8148 KB |
Output is correct |
16 |
Correct |
7 ms |
8148 KB |
Output is correct |
17 |
Correct |
9 ms |
8136 KB |
Output is correct |
18 |
Correct |
1 ms |
212 KB |
Output is correct |
19 |
Correct |
1 ms |
320 KB |
Output is correct |
20 |
Correct |
0 ms |
340 KB |
Output is correct |
21 |
Correct |
0 ms |
340 KB |
Output is correct |
22 |
Correct |
0 ms |
328 KB |
Output is correct |
23 |
Correct |
0 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
340 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
340 KB |
Output is correct |
29 |
Correct |
1 ms |
324 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Incorrect |
3 ms |
2644 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |