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;
const ll INF=1e17;
ll n,m;
ll lin[100005],col[100005],dp[1005][1005];
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(0);
cin>>n>>m;
for(int i=1;i<=n;i++)
cin>>lin[i];
for(int i=1;i<=m;i++)
cin>>col[i];
for(int i=1;i<=n;i++)
for(int j=1;j<=m;j++)
if(i!=1||j!=1)
{
dp[i][j]=INF;
if(i>1)
dp[i][j]=min(dp[i][j],dp[i-1][j]+col[j]);
if(j>1)
dp[i][j]=min(dp[i][j],dp[i][j-1]+lin[i]);
}
cout<<dp[n][m];
return 0;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |