Submission #994916

#TimeUsernameProblemLanguageResultExecution timeMemory
994916emptypringlescanJobs (BOI24_jobs)C++17
0 / 100
247 ms60756 KiB
#include <bits/stdc++.h> using namespace std; vector<pair<int,long long> > adj[300005]; set<pair<long long,long long> > s[300005]; void greed(int x){ for(auto i:adj[x]){ greed(i.first); if(i.second>=0){ s[i.first].insert({0,i.second}); } else{ pair<long long,long long> ins={-i.second,i.second}; while(ins.second<0||(!s[i.first].empty()&&s[i.first].begin()->first<=ins.first)){ if(s[i.first].empty()) break; ins.second+=s[i.first].begin()->second; ins.first=max(ins.first,s[i.first].begin()->first-i.second); s[i.first].erase(s[i.first].begin()); } if(ins.second>0) s[i.first].insert(ins); } if(s[i.first].size()>s[x].size()) swap(s[i.first],s[x]); for(auto j:s[i.first]) s[x].insert(j); s[i.first].clear(); } } int32_t main(){ ios::sync_with_stdio(0); cin.tie(0); long long n,m; cin >> n >> m; for(int i=1; i<=n; i++){ long long a,b; cin >> a >> b; adj[b].push_back({i,a}); } greed(0); long long org=m; for(auto i:s[0]){ if(m>=i.first) m+=i.second; } cout << m-org; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...