Submission #1040393

#TimeUsernameProblemLanguageResultExecution timeMemory
1040393vjudge1Divide and conquer (IZhO14_divide)C++17
100 / 100
19 ms6124 KiB
#include <bits/stdc++.h>
using namespace std;

#define ff(i, a, b) for(auto i=(a); i<=(b); ++i)
#define ffr(i, b, a) for(auto i=(b); i>=(a); --i)
#define nl "\n"
#define ss " "
#define pb push_back
#define ppb pop_back()
#define pf push_front
#define ppf pop_front()
#define fi first
#define se second
#define sz(s) (int)s.size()
#define ms(a,x) memset(a, x, sizeof (a))
#define re exit(0)

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;

const ll mod=1e9+7, maxn=1e6+5, inf=1e18;

void rf(){
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    if(fopen("o.inp","r")){
        freopen("o.inp","r",stdin); freopen("o.out","w",stdout);
    }
}

int n;
ll x[maxn], d[maxn], g[maxn], f[maxn];

int main()
{
    rf();
    cin>>n;
    ff(i, 1, n)
    {
        cin>>x[i]>>g[i]>>d[i];
        g[i]+=g[i-1]; d[i]+=d[i-1];

         f[i]=x[i]-d[i-1];
    }
    ff(i, 2, n) f[i]=max(f[i], f[i-1]);
    ll ans=0;
    ff(i, 1, n)
    {
        int l=1, r=i, id=-1;
        ll t=x[i]-d[i];
        while(l<=r)
        {
            int mid=(l+r)>>1;
            if(f[mid]>=t) id=mid, r=mid-1;
            else l=mid+1;
        }
        if(id+1) ans=max(ans, g[i]-g[id-1]);
    }
    cout<<ans;
    re;
}

Compilation message (stderr)

divide.cpp: In function 'void rf()':
divide.cpp:34:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         freopen("o.inp","r",stdin); freopen("o.out","w",stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~
divide.cpp:34:44: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   34 |         freopen("o.inp","r",stdin); freopen("o.out","w",stdout);
      |                                     ~~~~~~~^~~~~~~~~~~~~~~~~~~~
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...