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 vec vector
#define int long long
int32_t main() {
int N, S;
cin >> N >> S;
vec<int> X(N), P(N);
for(int i = 0; i<N; i++) {
cin >> X[i] >> P[i];
}
map<int, int> thrs;
int i = 0;
while(i<N) {
int s = i;
while(++i < N && P[i] != 0) {};
int e = i;
int pref_sum_mx = 0;
int pref_sum_mx_prev = 0;
int pref_sum_mn = 0;
int pref_sum = 0;
for(int j = s; j<e; j++) {
//cerr << X[i] << ' ';
pref_sum += X[j];
pref_sum_mx = max(pref_sum_mx, pref_sum);
pref_sum_mn = min(pref_sum_mn, pref_sum);
thrs[-pref_sum_mn] += (pref_sum_mx-pref_sum_mx_prev);
pref_sum_mx_prev = pref_sum_mx;
}
//cerr << '\n';
}
int money = S;
for(auto [t, g] : thrs) {
if(money >= t) {
money += g;
}
else {
break;
}
}
cout << money - S << '\n';
}
# | 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... |