Submission #1083566

#TimeUsernameProblemLanguageResultExecution timeMemory
1083566raczekJobs (BOI24_jobs)C++17
14 / 100
2095 ms1048576 KiB
#include<bits/stdc++.h> using namespace std; #ifdef DEBUG auto&operator <<(auto& o, pair<auto, auto> p) {return o<<"("<<p.first<<", "<<p.second<<")";} auto operator <<(auto& o, auto x)->decltype(x.end(), o) {o<<"{"; for(auto v : x) o<<v<<", "; return o<<"}";} #define debug(X) cout<<"["#X"]"<<X<<endl; #else #define debug(X) {} #endif #define int long long const int INF = numeric_limits<int>::max(); int32_t main() { ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); int n, s; cin>>n>>s; vector<vector<int> > graph(n+1); vector<int> cost(n+1); for(int i=1;i<=n;i++) { int c, p; cin>>c>>p; graph[p].push_back(i); cost[i] = c; } vector<vector<pair<int, int> > > pool(n+1); function<void(int)> dfs = [&](int b){ priority_queue<pair<int, int> > q; for(auto v : graph[b]) {dfs(v); q.push({pool[v].back().second, v});}; vector<pair<int, int> > myP = {{cost[b], 0}}; while(!q.empty()) { auto a = q.top().second; q.pop(); myP.push_back({pool[a].back().first, 0}); pool[a].pop_back(); if(pool[a].size() > 0) q.push({pool[a].back().second, a}); } int checkP = -1, akt = 0; for(int i=0;i<myP.size();i++) { akt += myP[i].first; if(akt >= 0) { akt -= myP[i].first; for(int j=checkP+1;j<=i;j++) { myP[j].second = akt; if(myP[j].first >= 0) myP[j].second = 0; akt -= myP[j].first; } checkP = i; akt = 0; } } for(int i=checkP+1;i<myP.size();i++) if(myP[i].first < 0) myP[i].second = -INF; reverse(myP.begin(), myP.end()); debug(b); debug(myP); pool[b] = myP; }; dfs(0); int org = s; while(pool[0].size()) { debug(pool[0].back()); if(pool[0].back().second + s < 0) break; if(s + pool[0].back().first >= 0) {s += pool[0].back().first; pool[0].pop_back();} } cout<<s - org; }

Compilation message (stderr)

Main.cpp: In lambda function:
Main.cpp:42:16: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   42 |   for(int i=0;i<myP.size();i++)
      |               ~^~~~~~~~~~~
Main.cpp:58:23: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   58 |   for(int i=checkP+1;i<myP.size();i++) if(myP[i].first < 0) myP[i].second = -INF;
      |                      ~^~~~~~~~~~~
#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...