제출 #344663

#제출 시각아이디문제언어결과실행 시간메모리
344663pragmatist금 캐기 (IZhO14_divide)C++14
100 / 100
37 ms5120 KiB
// turmak-_-
#include<bits/stdc++.h>

#define all(v) v.begin(),v.end()
#define sz(a) a.size()
#define nl "\n"
#define IOI return 0;
#define pb push_back
#define ppb pop_back()
#define ll long long
#define ull unsigned long long
#define ld long double
#define IOS ios_base :: sync_with_stdio(NULL); cin.tie(0); cout.tie(0);
#define pii pair<int,int>
#define X first
#define Y second


using namespace std;
const int N = (int)1e5 + 7 ;
const ll MOD = (ll)998244353;
const ll INF = (ll)1e18 + 7;
const int inf = (int)1e9 + 7;

pii dx[] = {{1, 0}, {-1, 0}, {0, 1}, {0, -1}};

ll x[N],g[N],d[N],p[N],p1[N],p2[N],mn[N];

void solve() {
    int n;
    cin>>n;

    ll mx = 0;
    mn[0]=INF;
    for(int i=1; i<=n; ++i) {
        cin>>x[i]>>g[i]>>d[i];
        if(d[i]>=1) mx = max(mx, g[i]);
        p[i]=p[i-1] + g[i];
        p1[i]=p1[i-1] + d[i];
        mn[i] = min(mn[i-1],p1[i-1]-x[i]);
    }
    for(int i=1; i<=n; ++i) {
        int l = 1, r = i, ans = i;
        while(l<=r) {
            int mid = (l+r)>>1;
            if(mn[mid]<=p1[i]-x[i]) {
                ans = mid;
                r = mid-1;
            } else {
                l = mid+1;
            }
        }
        mx = max(mx, p[i]-p[ans-1]);
    }
    cout<<mx<<nl;
}
int main() {
    IOS
    //freopen("cinema.in", "r", stdin);
    //freopen("cinema.out", "w", stdout);
    int tt=1;
    //  cin>>tt;
    while(tt--) {
        solve();
    }
    IOI
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...