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;
#define int long long
struct propo {
int gain,argMin,debSuiv,finSuiv;
bool operator < (const propo& autre) const {
return argMin>autre.argMin;
}
};
const int MAX_SOM=300*1000+5;
int nbSom,argDeb;
int val[MAX_SOM],pere[MAX_SOM];
priority_queue<propo> possi;
void calc(int deb,int fin) {
if (deb>fin) {
return;
}
int somCour=0,maxDeficit=0;
for (int i=deb;i<=fin;i++) {
somCour+=val[i];
maxDeficit=min(maxDeficit,somCour);
if (somCour>0) {
//cout<<"!"<<deb<<" "<<i<<endl;
possi.push({somCour,-maxDeficit,i+1,fin});
return;
}
}
//cout<<deb<<" "<<fin<<endl;
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>nbSom>>argDeb;
int deb=1;
for (int i=1;i<=nbSom;i++) {
cin>>val[i]>>pere[i];
if (pere[i]==0) {
calc(deb,i-1);
deb=i;
}
}
calc(deb,nbSom);
int argCour=argDeb;
propo nouv;
while (!possi.empty()) {
nouv=possi.top();
possi.pop();
if (argCour>=nouv.argMin) {
argCour+=nouv.gain;
calc(nouv.debSuiv,nouv.finSuiv);
}
}
cout<<argCour-argDeb<<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... |