Submission #995365

#TimeUsernameProblemLanguageResultExecution timeMemory
995365PagodePaivaJobs (BOI24_jobs)C++17
0 / 100
114 ms141896 KiB
#include<bits/stdc++.h> #define int long long using namespace std; const int N = 100010; int pai[N], val[N]; stack <pair <int, int>> s[N]; int32_t main(){ int n, c; cin >> n >> c; vector<int> aux; int con = 0; for(int i = 1;i <= n;i++){ cin >> val[i] >> pai[i]; if(pai[i] == 0){ if(!aux.empty()){ reverse(aux.begin(), aux.end()); vector <pair <int, int>> res; int ac = 0; int mnac = 0; while(!aux.empty()){ // cout << aux.back() << ' ' << ac << '\n'; if(aux.back() + ac >= 0){ ac = 0; res.push_back({aux.back()+ac, mnac}); mnac = 0; } else{ ac += aux.back(); mnac = min(mnac, ac); } aux.pop_back(); } for(auto x : res){ //cout << x.first << ' '; s[con].push(x); } con++; } } //cout << val[i] << ' '; aux.push_back(val[i]); } if(!aux.empty()){ reverse(aux.begin(), aux.end()); vector <pair <int, int>> res; int ac = 0; int mnac = 0; while(!aux.empty()){ // cout << aux.back() << ' ' << ac << '\n'; if(aux.back() + ac >= 0){ res.push_back({aux.back()+ac, mnac}); ac = 0; mnac = 0; } else{ ac += aux.back(); mnac = min(mnac, ac); } aux.pop_back(); } for(auto x : res){ //cout << x.first << ' '; s[con].push(x); } con++; } priority_queue <array <int, 3>> pq; for(int i = 0;i < con;i++){ if(s[i].empty()) continue; pq.push({s[i].top().second, s[i].top().first, i}); } int res = 0; while(!pq.empty()){ auto [mnac, valtot, i] = pq.top(); pq.pop(); // cout << mnac << ' '; if(c + mnac < 0) break; res += valtot; c += valtot; s[i].pop(); if(s[i].empty()) continue; pq.push({s[i].top().second, s[i].top().first, i}); } cout << res << '\n'; 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...