제출 #994961

#제출 시각아이디문제언어결과실행 시간메모리
994961emptypringlescanJobs (BOI24_jobs)C++17
11 / 100
268 ms59216 KiB
#include <bits/stdc++.h> using namespace std; vector<pair<int,long long> > adj[300005]; multiset<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(0ll,s[i.first].begin()->first-ins.first); 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(); } //cout << x << ":\n"; //for(auto i:s[x]) cout << i.first << ' ' << i.second << '\n'; } 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...