Submission #1053549

#TimeUsernameProblemLanguageResultExecution timeMemory
1053549ApiramJobs (BOI24_jobs)C++14
29 / 100
101 ms24128 KiB
/* * author : Apiram * created: 11.08.2024 14:11:10 */ #include<bits/stdc++.h> using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(0); long long n,s;cin>>n>>s; vector<pair<long long,long long>>arr(n + 1); vector<vector<long long>>adj(n + 1); for (long long i = 1;i<=n;++i){ cin>>arr[i].first>>arr[i].second; adj[arr[i].second].push_back(i); } long long k = s; priority_queue<pair<long long,long long>>q; for (auto x:adj[0]){ q.push({arr[x].first,x}); } while(!q.empty()){ auto u = q.top(); q.pop(); if (u.first > 0){ k+=u.first; for (auto x:adj[u.second]){ q.push({arr[x].first,x}); } } else if (k + u.first >= 0){ for (auto x:adj[u.second]){ q.push({arr[x].first + u.first,x}); } } else break; } cout<<k - s<<'\n'; return 0; }
#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...