#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int N = 5e3 + 10;
int n;
vector<int> G[N];
int a[N], h[N], c[N];
void compress() {
map<int, int> mp;
for(int i = 1; i <= n; i++)
mp[h[i]] = 1;
int k = 0;
for(auto &c : mp) {
c.second = k++;
}
for(int i = 1; i <= n; i++)
h[i] = mp[h[i]];
}
ll f[N][N];
int main() {
ios::sync_with_stdio(0);
cin.tie(0);cout.tie(0);
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> a[i];
cin >> h[i];
cin >> c[i];
if(a[i] < i) G[a[i]].push_back(i);
}
compress();
// for(int i = 1; i <= n; i++)
// cout << h[i] << ' ';
// cout << '\n';
for(int i = n; i >= 1; i--) {
vector<ll> g(n, c[i]);
g[h[i]] = 0;
for(int to : G[i]) {
for(int x = 0; x < n; x++) {
g[x] += f[to][x];
}
}
for(int x = n - 1; x >= 0; x--) {
f[i][x] = g[x];
if(x < n - 1) f[i][x] = min(f[i][x], f[i][x + 1]);
}
}
ll res = 1e18;
for(int x = 0; x < n - 1; x++)
res = min(res, f[1][x]);
cout << res;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
448 KB |
Output is correct |
3 |
Correct |
1 ms |
452 KB |
Output is correct |
4 |
Correct |
1 ms |
452 KB |
Output is correct |
5 |
Correct |
185 ms |
196820 KB |
Output is correct |
6 |
Correct |
179 ms |
196656 KB |
Output is correct |
7 |
Correct |
170 ms |
196824 KB |
Output is correct |
8 |
Correct |
172 ms |
196892 KB |
Output is correct |
9 |
Correct |
177 ms |
196800 KB |
Output is correct |
10 |
Correct |
171 ms |
196812 KB |
Output is correct |
11 |
Correct |
177 ms |
196744 KB |
Output is correct |
12 |
Correct |
173 ms |
197076 KB |
Output is correct |
13 |
Correct |
165 ms |
196848 KB |
Output is correct |
14 |
Correct |
167 ms |
196960 KB |
Output is correct |
15 |
Correct |
165 ms |
196840 KB |
Output is correct |
16 |
Correct |
176 ms |
197040 KB |
Output is correct |
17 |
Correct |
171 ms |
196748 KB |
Output is correct |
18 |
Correct |
172 ms |
196768 KB |
Output is correct |
19 |
Correct |
169 ms |
196996 KB |
Output is correct |
20 |
Correct |
171 ms |
196732 KB |
Output is correct |
21 |
Correct |
180 ms |
196696 KB |
Output is correct |
22 |
Correct |
174 ms |
196912 KB |
Output is correct |
23 |
Correct |
177 ms |
196668 KB |
Output is correct |
24 |
Correct |
167 ms |
196896 KB |
Output is correct |
25 |
Correct |
171 ms |
196828 KB |
Output is correct |
26 |
Correct |
171 ms |
196944 KB |
Output is correct |
27 |
Correct |
180 ms |
196908 KB |
Output is correct |
28 |
Correct |
171 ms |
197020 KB |
Output is correct |
29 |
Correct |
168 ms |
197096 KB |
Output is correct |
30 |
Correct |
164 ms |
196924 KB |
Output is correct |
31 |
Correct |
161 ms |
196864 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
448 KB |
Output is correct |
3 |
Correct |
1 ms |
452 KB |
Output is correct |
4 |
Correct |
1 ms |
452 KB |
Output is correct |
5 |
Correct |
185 ms |
196820 KB |
Output is correct |
6 |
Correct |
179 ms |
196656 KB |
Output is correct |
7 |
Correct |
170 ms |
196824 KB |
Output is correct |
8 |
Correct |
172 ms |
196892 KB |
Output is correct |
9 |
Correct |
177 ms |
196800 KB |
Output is correct |
10 |
Correct |
171 ms |
196812 KB |
Output is correct |
11 |
Correct |
177 ms |
196744 KB |
Output is correct |
12 |
Correct |
173 ms |
197076 KB |
Output is correct |
13 |
Correct |
165 ms |
196848 KB |
Output is correct |
14 |
Correct |
167 ms |
196960 KB |
Output is correct |
15 |
Correct |
165 ms |
196840 KB |
Output is correct |
16 |
Correct |
176 ms |
197040 KB |
Output is correct |
17 |
Correct |
171 ms |
196748 KB |
Output is correct |
18 |
Correct |
172 ms |
196768 KB |
Output is correct |
19 |
Correct |
169 ms |
196996 KB |
Output is correct |
20 |
Correct |
171 ms |
196732 KB |
Output is correct |
21 |
Correct |
180 ms |
196696 KB |
Output is correct |
22 |
Correct |
174 ms |
196912 KB |
Output is correct |
23 |
Correct |
177 ms |
196668 KB |
Output is correct |
24 |
Correct |
167 ms |
196896 KB |
Output is correct |
25 |
Correct |
171 ms |
196828 KB |
Output is correct |
26 |
Correct |
171 ms |
196944 KB |
Output is correct |
27 |
Correct |
180 ms |
196908 KB |
Output is correct |
28 |
Correct |
171 ms |
197020 KB |
Output is correct |
29 |
Correct |
168 ms |
197096 KB |
Output is correct |
30 |
Correct |
164 ms |
196924 KB |
Output is correct |
31 |
Correct |
161 ms |
196864 KB |
Output is correct |
32 |
Correct |
174 ms |
197020 KB |
Output is correct |
33 |
Runtime error |
9 ms |
1484 KB |
Execution killed with signal 6 |
34 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
492 KB |
Output is correct |
2 |
Correct |
1 ms |
448 KB |
Output is correct |
3 |
Correct |
1 ms |
452 KB |
Output is correct |
4 |
Correct |
1 ms |
452 KB |
Output is correct |
5 |
Correct |
185 ms |
196820 KB |
Output is correct |
6 |
Correct |
179 ms |
196656 KB |
Output is correct |
7 |
Correct |
170 ms |
196824 KB |
Output is correct |
8 |
Correct |
172 ms |
196892 KB |
Output is correct |
9 |
Correct |
177 ms |
196800 KB |
Output is correct |
10 |
Correct |
171 ms |
196812 KB |
Output is correct |
11 |
Correct |
177 ms |
196744 KB |
Output is correct |
12 |
Correct |
173 ms |
197076 KB |
Output is correct |
13 |
Correct |
165 ms |
196848 KB |
Output is correct |
14 |
Correct |
167 ms |
196960 KB |
Output is correct |
15 |
Correct |
165 ms |
196840 KB |
Output is correct |
16 |
Correct |
176 ms |
197040 KB |
Output is correct |
17 |
Correct |
171 ms |
196748 KB |
Output is correct |
18 |
Correct |
172 ms |
196768 KB |
Output is correct |
19 |
Correct |
169 ms |
196996 KB |
Output is correct |
20 |
Correct |
171 ms |
196732 KB |
Output is correct |
21 |
Correct |
180 ms |
196696 KB |
Output is correct |
22 |
Correct |
174 ms |
196912 KB |
Output is correct |
23 |
Correct |
177 ms |
196668 KB |
Output is correct |
24 |
Correct |
167 ms |
196896 KB |
Output is correct |
25 |
Correct |
171 ms |
196828 KB |
Output is correct |
26 |
Correct |
171 ms |
196944 KB |
Output is correct |
27 |
Correct |
180 ms |
196908 KB |
Output is correct |
28 |
Correct |
171 ms |
197020 KB |
Output is correct |
29 |
Correct |
168 ms |
197096 KB |
Output is correct |
30 |
Correct |
164 ms |
196924 KB |
Output is correct |
31 |
Correct |
161 ms |
196864 KB |
Output is correct |
32 |
Correct |
174 ms |
197020 KB |
Output is correct |
33 |
Runtime error |
9 ms |
1484 KB |
Execution killed with signal 6 |
34 |
Halted |
0 ms |
0 KB |
- |