제출 #1053457

#제출 시각아이디문제언어결과실행 시간메모리
1053457ApiramJobs (BOI24_jobs)C++14
0 / 100
8 ms11988 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); int n,s;cin>>n>>s; vector<pair<int,int>>arr(n + 1); vector<vector<int>>adj(n + 1); for (int i = 1;i<=n;++i){ cin>>arr[i].first>>arr[i].second; adj[arr[i].second].push_back(i); } vector<pair<int,int>>pos; function<void(int,int,int,int)>dfs = [&](int u,int mn,int profit,int cost){ if (profit > 0){ pos.push_back({mn,profit}); profit = 0; } for(auto x:adj[u]){ dfs(x,min(mn,cost + arr[x].first),profit + arr[x].first,cost + arr[x].first); } }; dfs(0,0,0,0); sort(pos.rbegin(),pos.rend()); int k = s; for (auto x:pos){ if (x.first + k < 0)break; k+=x.second; } 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...