제출 #914491

#제출 시각아이디문제언어결과실행 시간메모리
914491Tuanlinh123Worst Reporter 4 (JOI21_worst_reporter4)C++17
79 / 100
303 ms105228 KiB
#include<bits/stdc++.h> #define ll long long #define pll pair<ll, ll> #define pb push_back #define mp make_pair #define fi first #define se second #define ld long double using namespace std; const ll maxn=200005; ll H[maxn], C[maxn]; map <ll, ll> cnt[maxn]; vector <ll> A[maxn]; void dfs(ll u) { for (ll v:A[u]) { dfs(v); if (cnt[u].size()<cnt[v].size()) swap(cnt[u], cnt[v]); for (pll i:cnt[v]) cnt[u][i.fi]+=i.se; } ll crr=C[u]; cnt[u][H[u]]+=crr; auto it=cnt[u].lower_bound(H[u]); while (it!=cnt[u].begin()) { it--; if ((*it).se>crr) {(*it).se-=crr;break;} crr-=(*it).se; it=cnt[u].erase(it); } // cout << u << "\n"; // for (pll i:cnt[u]) cout << i.fi << " " << i.se << "\n"; } int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); ll n, sum=0; cin >> n; for (ll i=1; i<=n; i++) { ll a; cin >> a; if (i!=1) A[a].pb(i); cin >> H[i] >> C[i]; sum+=C[i]; } dfs(1); for (pll i:cnt[1]) sum-=i.se; cout << sum << "\n"; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...