- Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathThreeDisplays.cpp
63 lines (47 loc) · 1.14 KB
/
ThreeDisplays.cpp
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
// problem: https://codeforces.com/contest/987/problem/C
#include<bits/stdc++.h>
usingnamespacestd;
constlonglongint inf = 10000000000;
constint MAX = 3002;
longlongint lista[MAX];
longlongint custo[MAX];
longlongint dp[MAX][4];
longlongint c, a, ans;
int n;
longlongintbruto(int i, int ant, int rest){
if(rest == 0)
return0;
if(i == n+1)
return inf;
if(lista[i] > lista[ant]){
if(dp[i][rest] == inf)
dp[i][rest] = bruto(i + 1, i, rest - 1) + custo[i];
c = bruto(i + 1, ant, rest);
returnmin(dp[i][rest], c);
} else
returnbruto( i + 1, ant, rest);
}
voidprep(){
for(int i = 0; i < n+2; i++)
for(int j = 0; j < 4; j++)
dp[i][j] = inf;
}
intmain() {
ios_base::sync_with_stdio(false); cin.tie(0);
cin >> n;
for(int i = 1; i < n+1; i++){
cin >> a;
lista[i] = a;
}
for(int i = 1; i < n+1; i++){
cin >> a;
custo[i] = a;
}
prep();
ans = bruto(1, 0, 3);
if(ans < inf)
cout << ans;
else
cout << -1;
cout << endl;
}