Submission #1039902

#TimeUsernameProblemLanguageResultExecution timeMemory
1039902juicyWorst Reporter 4 (JOI21_worst_reporter4)C++17
79 / 100
249 ms524288 KiB
#include <bits/stdc++.h> using namespace std; #ifdef LOCAL #include "debug.h" #else #define debug(...) 42 #endif const int N = 2e5 + 5; int n; int a[N], c[N], dp[N]; vector<int> g[N]; map<int, long long> mp[N]; void dfs(int u) { for (int v : g[u]) { dfs(v); if (mp[u].size() < mp[v].size()) { mp[u].swap(mp[v]); } for (auto [x, y] : mp[v]) { mp[u][x] += y; } } mp[u][a[u]] += c[u]; for (auto it = mp[u].upper_bound(a[u]); it != mp[u].end(); it = mp[u].erase(it)) { auto &delta = (*it).second; if (c[u] < delta) { delta -= c[u]; break; } c[u] -= delta; } } int main() { ios::sync_with_stdio(false); cin.tie(nullptr); cin >> n; long long res = 0; for (int i = 1; i <= n; ++i) { int p; cin >> p >> a[i] >> c[i]; a[i] = 1e9 - a[i] + 1; res += c[i]; if (p ^ i) { g[p].push_back(i); } } dfs(1); for (auto [x, y] : mp[1]) { res -= y; } cout << res; return 0; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...