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 ll long long
ll a[100005], b[100005], c[100005], d[100005], e[100005];
vector<pair<ll, ll> > vec;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll n, ans=0;
cin >> n;
for (ll i=1; i<=n; i++)
{
ll x, y, num;
cin >> a[i] >> x >> y;
b[i]=b[i-1]+x;
c[i]=c[i-1]+y;
num=c[i]-a[i];
while (vec.size() && vec[vec.size()-1].first<=num)
vec.pop_back();
vec.push_back({num, i});
}
reverse(vec.begin(), vec.end());
for (ll i=0; i<vec.size(); i++)
{
d[i]=vec[i].first;
e[i]=vec[i].second;
}
for (ll i=1; i<=n; i++)
{
ll ind=lower_bound(d, d+vec.size(), c[i-1]-a[i])-d;
ans=max(ans, b[e[ind]]-b[i-1]);
}
cout << ans;
return 0;
}
Compilation message (stderr)
divide.cpp: In function 'int main()':
divide.cpp:25:19: warning: comparison of integer expressions of different signedness: 'long long int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
25 | for (ll i=0; i<vec.size(); i++)
| ~^~~~~~~~~~~
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |