Submission #1052835

#TimeUsernameProblemLanguageResultExecution timeMemory
1052835vjudge1Jobs (BOI24_jobs)C++17
0 / 100
21 ms27460 KiB
#include <bits/stdc++.h> using namespace std; int main() { int n,s; cin>>n>>s; int a[n+1],p[n+1]; vector<int> v; for (int i=1;i<=n;i++) cin>>a[i]>>p[i]; vector<vector<int>> prt; for (int i=1;i<=n;i++) { if (!p[i]) { if (!v.empty()) prt.push_back(v); v.clear(); } v.push_back(i); } prt.push_back(v); vector<pair<int,int>> pos; for (auto v:prt) { int mn=0,su=0; for (int i:v) { su+=a[i]; mn=min(mn,su); pos.push_back({mn,su}); } } int ans=0; while (!pos.empty()) { auto p=pos.back(); pos.pop_back(); if (p.first+s<0) break; if (p.second>0) { s+=p.second; ans+=p.second; } } cout<<ans<<endl; 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...