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;
typedef long long ll;
typedef long double ld;
#define F first
#define S second
#define pb push_back
#define sz(a) (int)a.size()
#define all(x) (x).begin(), (x).end()
vector<vector<ll>> v;
ll h, w; vector<ll> x, y;
ll f(ll a, ll b){
if(a<0 || a>=h || b<0 || b>=w) return -1;
return v[a][b];
}
int main() {
cin >> h >> w;
x.resize(h); y.resize(w);
for(auto& u : x) cin >> u;
for(auto& u : y) cin >> u;
v.assign(h+1, vector<ll>(w+1, -1));
v[0][0]=0;
for(ll i=0; i<h; i++){
for(ll j=0; j<w; j++){
if(i==0 && j==0) continue;
ll a=f(i-1, j), b=f(i, j-1);
if(a==-1) v[i][j]=b+x[i];
else if(b==-1) v[i][j]=a+y[j];
else v[i][j]=min(a+y[j], b+x[i]);
}
}
cout << v[h-1][w-1] << endl;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |