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 int MAXN = 1000;
const ll inf = 1e18;
ll grid[MAXN][MAXN];
int cost[MAXN][2];
int n, m;
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> cost[i][0];
for (int i = 0; i < m; i++) cin >> cost[i][1];
grid[0][0] = 0;
for (int i = 0; i < n; i++) {
for (int j = 0; j < m; j++) {
if (i+j == 0) continue;
grid[i][j] = inf;
if (i) grid[i][j] = min(grid[i][j], grid[i-1][j]+cost[j][1]);
if (j) grid[i][j] = min(grid[i][j], grid[i][j-1]+cost[i][0]);
}
}
cout << grid[n-1][m-1] << "\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... |