Codeforces Round #765 (Div. 2) C. Road Optimization

题目链接:​​​​​​Problem - C - Codeforces

The Government of Mars is not only interested in optimizing space flights, but also wants to improve the road system of the planet.

One of the most important highways of Mars connects Olymp City and Kstolop, the capital of Cydonia. In this problem, we only consider the way from Kstolop to Olymp City, but not the reverse path (i. e. the path from Olymp City to Kstolop).

The road from Kstolop to Olymp City is ℓℓ kilometers long. Each point of the road has a coordinate xx (0≤x≤ℓ0≤x≤ℓ), which is equal to the distance from Kstolop in kilometers. So, Kstolop is located in the point with coordinate 00, and Olymp City is located in the point with coordinate ℓℓ.

There are nn signs along the road, ii-th of which sets a speed limit aiai. This limit means that the next kilometer must be passed in aiai minutes and is active until you encounter the next along the road. There is a road sign at the start of the road (i. e. in the point with coordinate 00), which sets the initial speed limit.

If you know the location of all the signs, it's not hard to calculate how much time it takes to drive from Kstolop to Olymp City. Consider an example:

Here, you need to drive the first three kilometers in five minutes each, then one kilometer in eight minutes, then four kilometers in three minutes each, and finally the last two kilometers must be passed in six minutes each. Total time is 3⋅5+1⋅8+4⋅3+2⋅6=473⋅5+1⋅8+4⋅3+2⋅6=47 minutes.

To optimize the road traffic, the Government of Mars decided to remove no more than kk road signs. It cannot remove the sign at the start of the road, otherwise, there will be no limit at the start. By removing these signs, the Government also wants to make the time needed to drive from Kstolop to Olymp City as small as possible.

The largest industrial enterprises are located in Cydonia, so it's the priority task to optimize the road traffic from Olymp City. So, the Government of Mars wants you to remove the signs in the way described above.

Input

The first line contains three integers nn, ℓℓ, kk (1≤n≤5001≤n≤500, 1≤ℓ≤1051≤ℓ≤105, 0≤k≤n−10≤k≤n−1), the amount of signs on the road, the distance between the cities and the maximal number of signs you may remove.

The second line contains nn integers didi (d1=0d1=0, di<di+1di<di+1, 0≤di≤ℓ−10≤di≤ℓ−1) — coordinates of all signs.

The third line contains nn integers aiai (1≤ai≤1041≤ai≤104) — speed limits.

Output

Print a single integer — minimal possible time to drive from Kstolop to Olymp City in minutes, if you remove no more than kk road signs.

Examples

input

Copy

4 10 0
0 3 4 8
5 8 3 6

output

Copy

47

input

Copy

4 10 2
0 3 4 8
5 8 3 6

output

Copy

38

Note

In the first example, you cannot remove the signs. So the answer is 4747, as it's said in the statements above.

In the second example, you may remove the second and the fourth sign. In this case, you need to drive four kilometers in 4⋅5=204⋅5=20 minutes, and then six kilometers in 6⋅3=186⋅3=18, so the total time is 4⋅5+6⋅3=384⋅5+6⋅3=38 minutes.

题意:有n个路段,每个路段有个一个位置和距离,然后目标位置为t,现在可以删除k个路牌,问到目标的最短时间

思路:动态规划

状态表示:dp[i][j] 表示当前已经选到了第i个端点,且已经选了j个速度所用的最短时间

 状态转移:对于当前端点,直接枚举最后一次是由哪个端点的速度转移过来的

#include<bits/stdc++.h>
using namespace std;

int d[505];
int v[505];
int dp[505][505];

int main(){
	ios::sync_with_stdio(false);
	int n, m, k;
	while(cin >> n >> m >> k){
		for(int i = 1; i <= n; i++){
			cin >> d[i];
		}
		for(int i = 1; i <= n; i++){
			cin >> v[i];
		}
		d[++n] = m;
		for(int i = 0; i <= n; i++){
			for(int l = 0; l <= n; l++){
				dp[i][l] = 1e9;
			}
		}
		dp[1][1] = 0;
		for(int i = 2; i <= n; i++){ //选到第i个端点 
			for(int j = 1; j <= i; j++){ //已经选了j个速度 
				for(int l = 1; l < i; l++){ //枚举上一次的最后一个端点  
					dp[i][j] = min(dp[i][j], dp[l][j - 1] + (d[i] - d[l]) * v[l]);
				}
			}
		}
		int sum = 1e9;
		for(int i = 0; i <= k; i++){
			sum = min(sum, dp[n][n - i]);
		}
		cout << sum << endl;
	}
	return 0;
}

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值