Submission #1052890

#TimeUsernameProblemLanguageResultExecution timeMemory
1052890vjudge1Jobs (BOI24_jobs)C++17
11 / 100
204 ms79184 KiB
#include <bits/stdc++.h> using namespace std; #define ll long long #define vll vector<ll> #define all(x) begin(x),end(x) #define pb push_back const int N=3e5+10; ll pro[N],deg[N],par[N],mx[N],mi[N],sm[N]; vll ma[N]; set<vll> vals; void dfs(int x,int p=-1) { mx[x]=pro[x]; vals.insert({mi[x],sm[x],x}); for(auto y:ma[x]) { sm[y]=sm[x]+pro[y]; mi[y]=min(mi[x],sm[y]); dfs(y,x); mx[x]+=mx[y]; } if(mx[x]<0) mx[x]=0; } void solve() { ll n,s; cin>>n>>s; pro[0]=0; for(int i=1;i<=n;i++) { cin>>pro[i]>>par[i]; deg[i]++; ma[par[i]].pb(i); } ll mp=1e18; dfs(0); par[0]=-1; if(s==mp) { cout<<mx[0]<<endl; } else{ ll og=s; while(vals.size()>0) { auto it=*rbegin(vals); vals.erase(--end(vals)); if((it[1]<=0)) { // profit is non-positive so what is the benefit } else if((s+it[0])>=0){ // We can claim this s+=it[1]; // rem all before it ll cur=it[2]; while(cur!=-1) { auto it1=vals.find({mi[cur],sm[cur],cur}); if(it1!=vals.end()) vals.erase(it1); cur=par[cur]; } } } cout<<s-og<<endl; } } int main() { cin.tie(0);cout.tie(0); ios::sync_with_stdio(0); int t=1; // cin>>t; while(t--) solve(); }
#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...