Submission #1002368

#TimeUsernameProblemLanguageResultExecution timeMemory
1002368Valters07Jobs (BOI24_jobs)C++14
29 / 100
91 ms10944 KiB
#include <bits/stdc++.h> #pragma GCC optimize("O3,unroll-loops") #pragma GCC target("avx2,bmi,bmi2,popcnt,lzcnt") #define fio ios_base::sync_with_stdio(0);cin.tie(0); #define en cin.close();return 0; #define ll long long #define pb push_back #define fi first #define se second using namespace std; const int N = 3e5+5; int a[N]; bool st[N]; int main() { fio // ifstream cin("in.in"); int n; ll cash; cin >> n >> cash; ll c1 = cash; priority_queue<pair<pair<ll,ll>,int>,vector<pair<pair<ll,ll>,int> >,greater<pair<pair<ll,ll>,int> > > q; for(int i = 1,p;i<=n;i++) { cin >> a[i] >> p; if(p==0) { st[i]=1; q.push({{0,0},i}); } } st[n+1]=1; while(!q.empty()&&q.top().fi.fi<=cash) { cash+=q.top().fi.se; int pos = q.top().se; q.pop(); if(pos>n) continue; ll cur = 0, mi = 0; for(int i = pos;i==pos||!st[i];i++) { cur+=a[i]; mi=min(mi,cur); if(cur>0) { int nxt = (st[i+1]?n+1:i+1); q.push({{-mi,cur},nxt}); break; } } } cout << cash-c1; return 0; }
#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...