제출 #1053082

#제출 시각아이디문제언어결과실행 시간메모리
1053082vjudge1Jobs (BOI24_jobs)C++17
0 / 100
2068 ms36692 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; const ll N = 3e5 + 10; ll n, s, a[N], p[N]; vector<ll> outward[N], inward[N]; int main(){ cin >> n >> s; set<ll> st; for (ll i = 1; i <= n; i ++){ cin >> a[i] >> p[i]; if (!p[i]){ st.insert(i); continue; } outward[p[i]].push_back(i); inward[i].push_back(p[i]); } for (ll ii = 0; ii <= n * n; ii ++){ for (ll v : st){ ll u = v; ll sm = 0; ll mn = 0; while (1){ sm += a[v]; mn = min(mn, sm); if (outward[v].size()) v = outward[v][0]; else v = -1; if (sm >= 0 or v == -1){ break; } } if (sm < 0){ st.erase(u); break; } if (s + mn < 0) continue; st.erase(u); if (v != -1) st.insert(v); s += sm; break; } } cout << s << endl; }
#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...