This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#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 |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |