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>
#define int long long
using namespace std;
const int maxn = 1e3 + 10;
typedef pair<int,int> ii;
#define ff first
#define ss second
int n,m;
int a[maxn],b[maxn];
int dp[maxn][maxn];
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr); cout.tie(nullptr);
cin>>n>>m;
for (int i=1; i<=n; i++) cin>>a[i];
for (int j=1; j<=m; j++) cin>>b[j];
for (int i=0; i<=n; i++)
for (int j=0; j<=m; j++) dp[i][j] = 1e18;
dp[1][1] = 0;
for (int i=1; i<=n; i++)
for (int j=1; j<=m; j++)
{
if (i==1&&j==1) continue;
dp[i][j] = min(dp[i-1][j] + b[j], dp[i][j-1] + a[i]);
}
cout<<dp[n][m]<<'\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... |