Submission #570562

#TimeUsernameProblemLanguageResultExecution timeMemory
570562HanksburgerDivide and conquer (IZhO14_divide)C++17
100 / 100
45 ms8148 KiB
#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 (int i=0; i<vec.size(); i++)
    {
        d[i]=vec[i].first;
        e[i]=vec[i].second;
    }
    for (ll i=1; i<=n; i++)
    {
        int 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:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<std::pair<long long int, long long int> >::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   25 |     for (int i=0; i<vec.size(); i++)
      |                   ~^~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...