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;
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 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... |