This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e15;
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int h,w;
cin >> h >> w;
vector<int> a(h+1);
vector<int> b(w+1);
for(int i=1;i<=h;i++)cin>>a[i];
for(int i=1;i<=w;i++)cin>>b[i];
vector<vector<int>> DP(h+1,vector<int>(w+1,INF));
DP[1][1]=0;
for(int i=1;i<=h;i++){
for(int j=1;j<=w;j++){
if(j!=1)DP[i][j]=min(DP[i][j],DP[i][j-1]+a[i]);
if(i!=1)DP[i][j]=min(DP[i][j],DP[i-1][j]+b[j]);
}
}
cout << DP[h][w] << '\n';
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |