-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC_Road_Optimization.cpp
More file actions
38 lines (30 loc) · 911 Bytes
/
C_Road_Optimization.cpp
File metadata and controls
38 lines (30 loc) · 911 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#include <bits/stdc++.h>
using namespace std;
// First you make it work, then you can always make it beautiful
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int n, l, k;
cin >> n >> l >> k;
vector<int> d(n + 1), a(n);
for(int i=0;i<n;i++) cin >> d[i];
for(int i=0;i<n;i++) cin >> a[i];
d[n] = l;
vector<vector<int>> dp(k + 1, vector<int>(n + 1));
vector<vector<int>> dp2(k + 1, vector<int>(n + 1));
for(int i=n-1;i>=0;i--) {
for(int k1 = 0; k1 <= i; k1++) {
for(int j=0;j<=k;j++) {
int dist = d[i+1] - d[i];
dp[j][k1] = dist * a[i] + dp2[j][i];
if(j >= 1) {
dp[j][k1] = min(dp[j][k1], dist * a[k1] + dp2[j-1][k1]);
}
}
}
dp2 = dp;
}
cout << dp[k][0] << '\n';
return 0;
}