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>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(v) v.begin(), v.end()
#define F first
#define S second
typedef pair<int, int> pii;
typedef long long ll;
const int N=1e3+5;
int n, m, a[N], b[N];
ll dp[N][N];
int main(){
ios_base::sync_with_stdio(0); cin.tie(0);
cin>>n>>m;
if(n>1000)
return 0;
for(int i=0;i<n;++i){
cin>>a[i];
}
for(int i=0;i<m;++i){
cin>>b[i];
}
for(int i=0;i<n;++i)
fill(dp[i], dp[i]+m, 1e18);
dp[0][0]=0;
for(int i=0;i<n;++i){
for(int j=0;j<m;++j){
if(i>0)
dp[i][j]=dp[i-1][j]+b[j];
if(j>0)
dp[i][j]=min(dp[i][j], dp[i][j-1]+a[i]);
}
}
cout<<dp[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... |