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 F first
#define S second
#define in insert
#define er erase
#define pb push_back
#define ppb pop_back()
#define ph push
#define pp pop()
#define d3 ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define cans cout << ans << "\n";
#define yes cout << "YES" << "\n";
#define no cout << "NO" << "\n";
#define pll pair<ll,ll>
#define lin cout << "\n";
#define sqr 340
#define mod 1000000007
using namespace std;
ll fp(ll x , ll y)
{
if(y==0)
return 1;
ll z = fp(x,y/2);
if(y&1)
return z*z*x;
else
return z*z;
}
ll grid[1009][1009];
int main()
{
d3
ll h , w;
cin >> h >> w;
ll a[h];
ll b[w];
for(int i = 0 ; h>i ; i++)
cin >> a[i];
for(int i = 0 ; w>i ; i++)
cin >> b[i];
grid[0][0]=0;
for(int i = 1 ; h>i ; i++)
grid[i][0]=i*b[0];
for(int i = 1 ; w>i ; i++)
grid[0][i]=i*a[0];
for(int i = 1 ; h>i ; i++)
for(int j = 1 ; w>j ; j++)
grid[i][j]=min(grid[i-1][j]+b[j],grid[i][j-1]+a[i]);
cout << grid[h-1][w-1];
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |