#include <bits/stdc++.h>
using namespace std;
signed main(){
ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//freopen("input.txt","r",stdin);
//freopen("out.txt","w",stdout);
long long n,m;cin>>n>>m;
long long ro[n+1],co[m+1];
for(int i = 1;i<=n;i++)cin>>ro[i];
for(int i = 1;i<=m;i++)cin>>co[i];
long long dp[n+1][n+1];
for(int i = 1;i<=n;i++){
for(int j = 1;j<=m;j++){
dp[i][j] = 1e18;
if(i==1&&j==1)dp[i][j] = 0;
if(i>1)dp[i][j] = min(dp[i][j],dp[i-1][j]+co[j]);
if(j>1)dp[i][j] = min(dp[i][j],dp[i][j-1]+ro[i]);
}
}
cout<<dp[n][n]<<endl;
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
348 KB |
Output is correct |
2 |
Correct |
1 ms |
348 KB |
Output is correct |
3 |
Incorrect |
2 ms |
1116 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
0 ms |
344 KB |
Output is correct |
2 |
Correct |
0 ms |
344 KB |
Output is correct |
3 |
Incorrect |
0 ms |
348 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |