Submission #1098093

#TimeUsernameProblemLanguageResultExecution timeMemory
1098093_8_8_Jobs (BOI24_jobs)C++17
0 / 100
64 ms39660 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const int N = 2e5 + 12, MOD = (int)1e9 + 7; int n, p[N], x[N]; ll s, d[N]; vector<int> g[N], rt, ord[N]; void prec(int v) { d[v] = x[v]; for(int to:g[v]) { prec(to); if(d[to] < 0) continue; d[v] += d[to]; } } void dfs(int v) { if(d[v] < 0) return; vector<int> f; for(int to:g[v]) { dfs(to); vector<int> nv; int l = 0, r = 0; while(l < (int)f.size() || r < (int)ord[to].size()) { if(l == (int)f.size() || (r != ord[to].size() && x[ord[to][r]] > x[f[l]])) { nv.push_back(ord[to][r]); r++; } else { nv.push_back(f[l]); l++; } } f = nv; } ord[v].push_back(v); for(auto j:f) { ord[v].push_back(j); } } void test() { cin >> n >> s; for(int i = 1; i <= n; i++) { cin >> x[i] >> p[i]; g[p[i]].push_back(i); } prec(0); dfs(0); ll st = s, en = s, mx = s; for(int i:ord[0]) { en += x[i]; if(en < 0) break; mx = max(mx, en); } cout << mx - st << '\n'; } int main() { ios_base::sync_with_stdio(false); cin.tie(0); int t = 1; // cin >> t; while(t--) test(); return 0; }

Compilation message (stderr)

Main.cpp: In function 'void dfs(int)':
Main.cpp:29:41: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   29 |             if(l == (int)f.size() || (r != ord[to].size() && x[ord[to][r]] > x[f[l]])) {
      |                                       ~~^~~~~~~~~~~~~~~~~
#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...