Submission #1063072

#TimeUsernameProblemLanguageResultExecution timeMemory
1063072antonJobs (BOI24_jobs)C++17
0 / 100
138 ms23280 KiB
#include<bits/stdc++.h> using namespace std; #define int long long #define pii pair<int, int> const int MAX_N = 3e5+1; int N, S; vector<vector<int>> seq; signed main(){ cin>>N>>S; for(int i = 0; i<N; i++){ int x, p; cin>>x>>p; if(i>0 && p==i){ seq.back().push_back(x); } else{ seq.push_back({x}); } } vector<pii> pq; for(auto s: seq){ int prev_max =0; int pref_s = 0; int min_on_path = 1e18; for(auto e: s){ pref_s+=e; min_on_path = min(min_on_path, pref_s); if(pref_s>prev_max){ pq.push_back({ min_on_path, pref_s-prev_max}); prev_max= pref_s; } } } int initS = S; sort(pq.begin(), pq.end()); while(pq.size()>0){ pii e = pq.back(); pq.pop_back(); if(S+e.first<0){ break; } else{ S+= e.second; } } cout<<S-initS<<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...