#include<bits/stdc++.h>
#define fi first
#define se second
#define eb emplace_back
#define ep emplace
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
const ll INF=1e18;
const ll mod=1e9+7;
const ll mxn=1005;
int h,w,a[mxn],b[mxn];
ll dp[mxn][mxn];
int main()
{
ios::sync_with_stdio(0); cin.tie(0);
cin>>h>>w;
for (int i=1;i<=h;i++) cin>>a[i];
for (int i=1;i<=w;i++) cin>>b[i];
for (int i=1;i<=h;i++)
for(int j=1;j<=w;j++)
{
if(i==1 && j==1) continue;
ll x=(i>1?dp[i-1][j]+b[j]:INF);
ll y=(j>1?dp[i][j-1]+a[i]:INF);
dp[i][j]=min(x,y);
}
cout<<dp[h][w];
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 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 |
1540 KB |
Output is correct |
7 |
Correct |
1 ms |
1096 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
7 ms |
8232 KB |
Output is correct |
10 |
Correct |
7 ms |
8148 KB |
Output is correct |
11 |
Correct |
7 ms |
8148 KB |
Output is correct |
12 |
Correct |
9 ms |
8208 KB |
Output is correct |
13 |
Correct |
7 ms |
8148 KB |
Output is correct |
14 |
Correct |
7 ms |
8148 KB |
Output is correct |
15 |
Correct |
7 ms |
8124 KB |
Output is correct |
16 |
Correct |
7 ms |
8148 KB |
Output is correct |
17 |
Correct |
7 ms |
8160 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 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 |
1 ms |
324 KB |
Output is correct |
26 |
Correct |
1 ms |
328 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
324 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 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 |
1 ms |
340 KB |
Output is correct |
2 |
Correct |
0 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 |
1540 KB |
Output is correct |
7 |
Correct |
1 ms |
1096 KB |
Output is correct |
8 |
Correct |
1 ms |
468 KB |
Output is correct |
9 |
Correct |
7 ms |
8232 KB |
Output is correct |
10 |
Correct |
7 ms |
8148 KB |
Output is correct |
11 |
Correct |
7 ms |
8148 KB |
Output is correct |
12 |
Correct |
9 ms |
8208 KB |
Output is correct |
13 |
Correct |
7 ms |
8148 KB |
Output is correct |
14 |
Correct |
7 ms |
8148 KB |
Output is correct |
15 |
Correct |
7 ms |
8124 KB |
Output is correct |
16 |
Correct |
7 ms |
8148 KB |
Output is correct |
17 |
Correct |
7 ms |
8160 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
0 ms |
340 KB |
Output is correct |
20 |
Correct |
1 ms |
340 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 |
1 ms |
324 KB |
Output is correct |
26 |
Correct |
1 ms |
328 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
324 KB |
Output is correct |
29 |
Correct |
1 ms |
340 KB |
Output is correct |
30 |
Correct |
0 ms |
340 KB |
Output is correct |
31 |
Incorrect |
3 ms |
2644 KB |
Output isn't correct |
32 |
Halted |
0 ms |
0 KB |
- |