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 MAXX 1007
long long dp[MAXX][MAXX];
long long a[MAXX],b[MAXX];
int h,w;
long long fun(int h1,int w1)
{
if (h1==1 && w1==1) return 0;
if (dp[h1][w1]!=0) return dp[h1][w1];
if (h1==1)
{
dp[h1][w1]=fun(h1,w1-1)+a[h1];
return dp[h1][w1];
}
if (w1==1)
{
dp[h1][w1]=fun(h1-1,w1)+b[w1];
return dp[h1][w1];
}
dp[h1][w1]=min(fun(h1,w1-1)+a[h1],fun(h1-1,w1)+b[w1]);
return dp[h1][w1];
}
int main()
{
cin>>h>>w;
for (int q=1;q<=h;q++) cin>>a[q];
for (int q=1;q<=w;q++) cin>>b[q];
cout<<fun(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... |