#include<bits/stdc++.h>
using namespace std;
#define int long long
#define X first
#define Y second
int H;int W;
int dp[2010][2010];
int ar[500005];
int br[500005];
signed main(){
cin>>H>>W;
for(int i=1;i<=H;i++){
cin>>ar[i];
}
for(int i=1;i<=W;i++){
cin>>br[i];
}
for(int i=1;i<=H;i++){
for(int j=1;j<=W;j++){
dp[i][j]=1e18;
}
}
dp[1][1]=0;
for(int i=1;i<=H;i++){
for(int j=1;j<=W;j++){
dp[i+1][j]=min(dp[i+1][j],dp[i][j]+br[j]);
dp[i][j+1]=min(dp[i][j+1],dp[i][j]+ar[i]);
}
}
cout<<dp[H][W];
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 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 |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
2260 KB |
Output is correct |
6 |
Correct |
1 ms |
1620 KB |
Output is correct |
7 |
Correct |
1 ms |
1128 KB |
Output is correct |
8 |
Correct |
1 ms |
304 KB |
Output is correct |
9 |
Correct |
7 ms |
12116 KB |
Output is correct |
10 |
Correct |
7 ms |
12200 KB |
Output is correct |
11 |
Correct |
8 ms |
12168 KB |
Output is correct |
12 |
Correct |
9 ms |
12112 KB |
Output is correct |
13 |
Correct |
7 ms |
12116 KB |
Output is correct |
14 |
Correct |
7 ms |
12116 KB |
Output is correct |
15 |
Correct |
7 ms |
12200 KB |
Output is correct |
16 |
Correct |
7 ms |
12116 KB |
Output is correct |
17 |
Correct |
7 ms |
12116 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
308 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 |
0 ms |
308 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
308 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
308 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
304 KB |
Output is correct |
3 |
Correct |
3 ms |
4564 KB |
Output is correct |
4 |
Runtime error |
56 ms |
66104 KB |
Execution killed with signal 11 |
5 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 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 |
980 KB |
Output is correct |
5 |
Correct |
1 ms |
2260 KB |
Output is correct |
6 |
Correct |
1 ms |
1620 KB |
Output is correct |
7 |
Correct |
1 ms |
1128 KB |
Output is correct |
8 |
Correct |
1 ms |
304 KB |
Output is correct |
9 |
Correct |
7 ms |
12116 KB |
Output is correct |
10 |
Correct |
7 ms |
12200 KB |
Output is correct |
11 |
Correct |
8 ms |
12168 KB |
Output is correct |
12 |
Correct |
9 ms |
12112 KB |
Output is correct |
13 |
Correct |
7 ms |
12116 KB |
Output is correct |
14 |
Correct |
7 ms |
12116 KB |
Output is correct |
15 |
Correct |
7 ms |
12200 KB |
Output is correct |
16 |
Correct |
7 ms |
12116 KB |
Output is correct |
17 |
Correct |
7 ms |
12116 KB |
Output is correct |
18 |
Correct |
1 ms |
340 KB |
Output is correct |
19 |
Correct |
1 ms |
308 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 |
0 ms |
308 KB |
Output is correct |
25 |
Correct |
1 ms |
340 KB |
Output is correct |
26 |
Correct |
1 ms |
308 KB |
Output is correct |
27 |
Correct |
1 ms |
340 KB |
Output is correct |
28 |
Correct |
1 ms |
308 KB |
Output is correct |
29 |
Correct |
1 ms |
212 KB |
Output is correct |
30 |
Correct |
1 ms |
304 KB |
Output is correct |
31 |
Correct |
3 ms |
4564 KB |
Output is correct |
32 |
Runtime error |
56 ms |
66104 KB |
Execution killed with signal 11 |
33 |
Halted |
0 ms |
0 KB |
- |