#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
namespace x = __gnu_pbds;
template <typename T>
using ordered_set = x::tree<T, x::null_type, less<T>, x::rb_tree_tag, x::tree_order_statistics_node_update>;
template <typename T>
using normal_queue = priority_queue<T, vector<T>, greater<>>;
#define all(x) begin(x), end(x)
#define sz(x) ((int) (x).size())
#define x first
#define y second
using ll = long long;
using ld = long double;
#define int ll
const int N = 1010, INF = 0x3f3f3f3f3f3f3f3f;
int a[N], b[N];
int dp[N][N];
signed main() {
cin.tie(0)->sync_with_stdio(0);
int n, m;
cin >> n >> m;
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
for (int i = 0; i < m; ++i) {
cin >> b[i];
}
fill(dp[0], dp[N], +INF);
dp[0][0] = 0;
for (int i = 0; i < n; ++i) {
for (int j = 0; j < m; ++j) {
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + b[j]);
dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + a[i]);
}
}
cout << dp[n - 1][m - 1];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8276 KB |
Output is correct |
2 |
Correct |
5 ms |
8276 KB |
Output is correct |
3 |
Correct |
5 ms |
8284 KB |
Output is correct |
4 |
Correct |
5 ms |
8276 KB |
Output is correct |
5 |
Correct |
5 ms |
8280 KB |
Output is correct |
6 |
Correct |
5 ms |
8276 KB |
Output is correct |
7 |
Correct |
4 ms |
8276 KB |
Output is correct |
8 |
Correct |
4 ms |
8264 KB |
Output is correct |
9 |
Correct |
10 ms |
8276 KB |
Output is correct |
10 |
Correct |
10 ms |
8276 KB |
Output is correct |
11 |
Correct |
8 ms |
8276 KB |
Output is correct |
12 |
Correct |
8 ms |
8252 KB |
Output is correct |
13 |
Correct |
8 ms |
8272 KB |
Output is correct |
14 |
Correct |
9 ms |
8340 KB |
Output is correct |
15 |
Correct |
9 ms |
8304 KB |
Output is correct |
16 |
Correct |
11 ms |
8276 KB |
Output is correct |
17 |
Correct |
11 ms |
8280 KB |
Output is correct |
18 |
Correct |
4 ms |
8268 KB |
Output is correct |
19 |
Correct |
4 ms |
8276 KB |
Output is correct |
20 |
Correct |
4 ms |
8276 KB |
Output is correct |
21 |
Correct |
4 ms |
8276 KB |
Output is correct |
22 |
Correct |
4 ms |
8276 KB |
Output is correct |
23 |
Correct |
4 ms |
8272 KB |
Output is correct |
24 |
Correct |
4 ms |
8268 KB |
Output is correct |
25 |
Correct |
4 ms |
8316 KB |
Output is correct |
26 |
Correct |
4 ms |
8208 KB |
Output is correct |
27 |
Correct |
6 ms |
8276 KB |
Output is correct |
28 |
Correct |
4 ms |
8276 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8276 KB |
Output is correct |
2 |
Correct |
4 ms |
8276 KB |
Output is correct |
3 |
Incorrect |
8 ms |
8276 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
4 ms |
8276 KB |
Output is correct |
2 |
Correct |
5 ms |
8276 KB |
Output is correct |
3 |
Correct |
5 ms |
8284 KB |
Output is correct |
4 |
Correct |
5 ms |
8276 KB |
Output is correct |
5 |
Correct |
5 ms |
8280 KB |
Output is correct |
6 |
Correct |
5 ms |
8276 KB |
Output is correct |
7 |
Correct |
4 ms |
8276 KB |
Output is correct |
8 |
Correct |
4 ms |
8264 KB |
Output is correct |
9 |
Correct |
10 ms |
8276 KB |
Output is correct |
10 |
Correct |
10 ms |
8276 KB |
Output is correct |
11 |
Correct |
8 ms |
8276 KB |
Output is correct |
12 |
Correct |
8 ms |
8252 KB |
Output is correct |
13 |
Correct |
8 ms |
8272 KB |
Output is correct |
14 |
Correct |
9 ms |
8340 KB |
Output is correct |
15 |
Correct |
9 ms |
8304 KB |
Output is correct |
16 |
Correct |
11 ms |
8276 KB |
Output is correct |
17 |
Correct |
11 ms |
8280 KB |
Output is correct |
18 |
Correct |
4 ms |
8268 KB |
Output is correct |
19 |
Correct |
4 ms |
8276 KB |
Output is correct |
20 |
Correct |
4 ms |
8276 KB |
Output is correct |
21 |
Correct |
4 ms |
8276 KB |
Output is correct |
22 |
Correct |
4 ms |
8276 KB |
Output is correct |
23 |
Correct |
4 ms |
8272 KB |
Output is correct |
24 |
Correct |
4 ms |
8268 KB |
Output is correct |
25 |
Correct |
4 ms |
8316 KB |
Output is correct |
26 |
Correct |
4 ms |
8208 KB |
Output is correct |
27 |
Correct |
6 ms |
8276 KB |
Output is correct |
28 |
Correct |
4 ms |
8276 KB |
Output is correct |
29 |
Correct |
4 ms |
8276 KB |
Output is correct |
30 |
Correct |
4 ms |
8276 KB |
Output is correct |
31 |
Incorrect |
8 ms |
8276 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |