Submission #1053000

#TimeUsernameProblemLanguageResultExecution timeMemory
1053000Sir_Ahmed_ImranJobs (BOI24_jobs)C++17
40 / 100
67 ms38844 KiB
///~~~LOTA~~~/// #include <bits/stdc++.h> using namespace std; #define ll long long #define ld long double #define append push_back #define add insert #define nl '\n' #define ff first #define ss second #define pii pair<int,int> #define pll pair<ll,ll> #define all(x) (x).begin(),(x).end() #define L0TA ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) #define terminator main #define N 300001 ll x[N]; ll y[N]; ll p[N]; ll dp[N]; ll val[N]; vector<int> a[N]; void dfs(int v){ dp[v]=val[v]; for(auto& i:a[v]){ dfs(i); dp[v]+=dp[i]; } dp[v]=max(dp[v],0LL); } void solve(){ ll n,m,s; cin>>n>>s; vector<pll> v; for(int i=1;i<=n;i++){ cin>>val[i]>>p[i]; a[p[i]].append(i); m=val[i]; if(x[p[i]]<0){ y[i]=max(y[p[i]],-x[p[i]]-m); x[i]=x[p[i]]+m; } else{ x[i]=m; y[i]=max(-m,y[p[i]]); } if(x[i]>0) v.append({y[i],x[i]}); } m=1e18; if(s==m){ dfs(0); cout<<dp[0]; return; } m=s; sort(all(v)); for(auto& i:v){ if(i.ff>m) break; m+=i.ss; } cout<<m-s; } int terminator(){ L0TA; solve(); 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...