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 MAX 500005
#define MOD (ll)(1e9+7)
#define INF (ll)(1e18)
#define inf (1987654321)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
int n, m, q;
int a[100005], b[100005];
ll dp[1005][1005];
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> n >> m;
for(int i = 1; i <= n; ++i) cin >> a[i];
for(int i = 1; i <= m; ++i) cin >> b[i];
for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j) dp[i][j] = INF;
dp[1][1] = 0;
for(int i = 1; i <= n; ++i) for(int j = 1; j <= m; ++j) {
dp[i][j + 1] = min(dp[i][j + 1], dp[i][j] + a[i]);
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j] + b[j]);
}
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... |