# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1026594 | Issa | Jobs (BOI24_jobs) | C++17 | 2064 ms | 25112 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define ent "\n"
const int maxn = 3e5 + 100;
const ll INF = (ll)1e18 + 100;
const int inf = 1e9 + 100;
const int MOD = 1e9 + 7;
const int maxl = 350;
const int P = 31;
ll sum, start;
int n;
vector<int> g[maxn];
int p[maxn];
int a[maxn];
ll mn[maxn];
ll sm[maxn];
int used[maxn];
void test(){
cin >> n >> start; sum = start;
for(int i = 1; i <= n; i++){
cin >> a[i] >> p[i];
g[p[i]].push_back(i);
}
used[0] = 1;
while(true){
for(int i = 1; i <= n; i++){
sm[i] = mn[i] = 0;
}
ll nxt = sum, f;
for(int v = 1; v <= n; v++){
if(used[v]) continue;
sm[v] += a[v];
mn[v] = min(mn[v], sm[v]);
for(int to: g[v]){
sm[to] = sm[v];
mn[to] = mn[v];
}
if(sum + mn[v] >= 0 && sum + sm[v] > nxt){
nxt = sum + sm[v]; f = v;
}
}
if(nxt > sum){
sum = nxt;
while(!used[f]){
used[f] = 1;
f = p[f];
}
} else break;
}
cout << sum - start;
}
int main(){
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t; t = 1;
while(t--) test();
cout << ent;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |