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 ll long long
#define ld long double
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pdd pair<double, double>
#define ALL(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector<ll>
#define SZ(x) (int)x.size()
#define CASE int t;cin>>t;for(int ca=1;ca<=t;ca++)
#define IOS ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int MAX = 1007, MOD = 1e9 + 7;
ll a[MAX], b[MAX], dp[MAX][MAX];
void solve(){
int n, m;
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] = 2e18;
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] << '\n';
}
int main(){
IOS
// CASE
solve();
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... |