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;
#define int long long
int n;
long long mon;
vector<pair<int,long long> > adj[300005];
long long off;
priority_queue<pair<long long,int> > pq;
int32_t main(){
ios::sync_with_stdio(0);
cin.tie(0);
cin >> n >> mon;
long long org=mon;
for(int i=1; i<=n; i++){
long long a,b;
cin >> a >> b;
adj[b].push_back({i,a});
}
pq.push({mon,0});
while(!pq.empty()){
pair<long long,int> x=pq.top();
pq.pop();
x.first+=off;
if(x.first<0) continue;
if(x.first>mon){
off+=x.first-mon;
mon=x.first;
}
for(auto i:adj[x.second]){
pq.push({x.first+i.second-off,i.first});
}
}
cout << mon-org;
}
# | 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... |