using
System;
using
System.Collections.Generic;
public
class
MinimumMoney
{
static
long
[,] dp =
new
long
[500, 1001];
static
long
Memo(
int
i,
int
t, List<
int
> price, List<
int
> time,
int
n)
{
if
(i >= n)
{
if
(t >= 0)
return
0;
return
(
long
)1e18;
}
if
(n - i <= t)
return
0;
if
(dp[i, t + 500] != -1)
return
dp[i, t + 500];
return
dp[i, t + 500] = Math.Min(Memo(i + 1, t + time[i], price, time, n) + price[i],
Memo(i + 1, t - 1, price, time, n));
}
static
long
MinCost(
int
n, List<
int
> p, List<
int
> f)
{
for
(
int
i = 0; i < 500; i++)
{
for
(
int
j = 0; j < 1001; j++)
{
dp[i, j] = -1;
}
}
return
Memo(0, 0, p, f, n);
}
public
static
void
Main(
string
[] args)
{
int
n = 4;
List<
int
> p =
new
List<
int
> { 10, 20, 5, 3 };
List<
int
> f =
new
List<
int
> { 2, 0, 1, 1 };
Console.WriteLine(MinCost(n, p, f));
}
}