이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#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 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... |