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>
#define ll long long
#define F first
#define S second
using namespace std;
ll dp[300010];
vector<pair<ll,ll>> vc;
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
ll n,s;
cin>>n>>s;
for(int i=0;i<n;i++){
ll a,b;
cin>>a>>b;
vc.push_back({a,b});
}
for(int i=n-1;i>=0;i--){
dp[i+1]+=vc[i].F;
dp[vc[i].S]+=max(0LL,dp[i+1]);
}
cout<<dp[0]<<"\n";
return 0;
}
# | 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... |