#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<double, double>
#define ALL(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector<ll>
#define SZ(x) (int)x.size()
#define CASE int t;cin>>t;for(int ca=1;ca<=t;ca++)
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int MAX = 1007, MOD = 1e9 + 7;
ll a[MAX], b[MAX], dp[MAX][MAX];
void solve(){
int n, m;
cin >> n >> m;
for(int i = 1;i <= n;i++){
cin >> a[i];
}
for(int i = 1;i <= m;i++){
cin >> b[i];
}
for(int i = 1;i <= n;i++)
for(int j = 1;j <= m;j++)
dp[i][j] = 2e18;
dp[1][1] = 0;
for(int i = 1;i <= n;i++){
for(int j = 1;j <= m;j++){
dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + a[i]);
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + b[j]);
}
}
cout << dp[n][m] << '\n';
}
int main(){
IOS
// CASE
solve();
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
2260 KB |
Output is correct |
6 |
Correct |
1 ms |
1612 KB |
Output is correct |
7 |
Correct |
1 ms |
1132 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
8 ms |
8152 KB |
Output is correct |
10 |
Correct |
9 ms |
8288 KB |
Output is correct |
11 |
Correct |
8 ms |
8148 KB |
Output is correct |
12 |
Correct |
8 ms |
8148 KB |
Output is correct |
13 |
Correct |
10 ms |
8148 KB |
Output is correct |
14 |
Correct |
10 ms |
8152 KB |
Output is correct |
15 |
Correct |
9 ms |
8152 KB |
Output is correct |
16 |
Correct |
9 ms |
8148 KB |
Output is correct |
17 |
Correct |
8 ms |
8148 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
328 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
26 |
Correct |
0 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 |
328 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Incorrect |
3 ms |
2772 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
324 KB |
Output is correct |
2 |
Correct |
1 ms |
340 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
1 ms |
724 KB |
Output is correct |
5 |
Correct |
1 ms |
2260 KB |
Output is correct |
6 |
Correct |
1 ms |
1612 KB |
Output is correct |
7 |
Correct |
1 ms |
1132 KB |
Output is correct |
8 |
Correct |
1 ms |
340 KB |
Output is correct |
9 |
Correct |
8 ms |
8152 KB |
Output is correct |
10 |
Correct |
9 ms |
8288 KB |
Output is correct |
11 |
Correct |
8 ms |
8148 KB |
Output is correct |
12 |
Correct |
8 ms |
8148 KB |
Output is correct |
13 |
Correct |
10 ms |
8148 KB |
Output is correct |
14 |
Correct |
10 ms |
8152 KB |
Output is correct |
15 |
Correct |
9 ms |
8152 KB |
Output is correct |
16 |
Correct |
9 ms |
8148 KB |
Output is correct |
17 |
Correct |
8 ms |
8148 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
328 KB |
Output is correct |
21 |
Correct |
1 ms |
340 KB |
Output is correct |
22 |
Correct |
1 ms |
340 KB |
Output is correct |
23 |
Correct |
1 ms |
340 KB |
Output is correct |
24 |
Correct |
1 ms |
340 KB |
Output is correct |
25 |
Correct |
0 ms |
340 KB |
Output is correct |
26 |
Correct |
0 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 |
328 KB |
Output is correct |
30 |
Correct |
1 ms |
340 KB |
Output is correct |
31 |
Incorrect |
3 ms |
2772 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |