Submission #528813

# Submission time Handle Problem Language Result Execution time Memory
528813 2022-02-21T13:49:36 Z perchuts Divide and conquer (IZhO14_divide) C++17
48 / 100
52 ms 7624 KB
#include <bits/stdc++.h>
#define maxn (int)(1e5+51)
#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define endl '\n'
#define ll long long
#define pb push_back
#define ull unsigned long long
#define ii pair<int,int>
#define iii tuple<int,int,int>
#define inf 2000000001
#define mod 1000000007 //998244353
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

using namespace std;

template<typename X, typename Y> bool ckmin(X& x, const Y& y) { return (y < x) ? (x=y,1):0; }
template<typename X, typename Y> bool ckmax(X& x, const Y& y) { return (x < y) ? (x=y,1):0; }
struct mine{
    ll x,g,e;
};

mine v[maxn];
ll pref[maxn];
int bit[maxn],n;

void insert(int x,int d){
    for(;x<=n+100;x+=x&(-x))ckmin(bit[x],d);
}

int query(int x){
    int ans = inf;
    while(x){
        ckmin(ans,bit[x]);
        x -= x&(-x);
    }
    return ans;
}

int main(){_
    cin>>n;
    for(int i=1;i<=n;++i){
        cin>>v[i].x>>v[i].g>>v[i].e;
    }
    for(int i=0;i<=n+100;++i)bit[i] = inf;
    vector<ll>cmp;
    ll sum = v[1].e;
    pref[1] = v[1].g;
    for(int i=2;i<=n;++i){
        sum -= abs(v[i-1].x - v[i].x);
        cmp.pb(sum);
        sum += v[i].e;
        pref[i] = pref[i-1] + v[i].g;
    }
    cmp.pb(0);
    sort(all(cmp));
    cmp.erase(unique(all(cmp)),cmp.end());
    // for(auto x:cmp)cout<<x<<" ";
    // cout<<endl;
    // for(int i=1;i<=n;++i)cout<<pref[i]<<" ";
    // cout<<endl;
    sum = v[1].e;
    ll ans = 0;
    for(int i=1;i<=n;++i){
        if(i!=1)sum += v[i].e - abs(v[i].x - v[i-1].x);
        int ind = lower_bound(all(cmp),sum) - begin(cmp) + 1;
        if(ind!=sz(cmp)+1&&cmp[ind-1]>sum)ind--;
        // cout<<ind<<" "<<sum<<endl;
        int q = min(i,query(ind));
        ckmax(ans,pref[i]-pref[q-1]);
        int ind2 = lower_bound(all(cmp),sum-v[i].e) - begin(cmp) + 1;
        insert(ind2,i);
    }
    // cout<<endl;
    cout<<ans<<endl;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 3 ms 716 KB Output is correct
24 Correct 3 ms 728 KB Output is correct
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 1 ms 332 KB Output is correct
3 Correct 0 ms 332 KB Output is correct
4 Correct 0 ms 332 KB Output is correct
5 Correct 0 ms 204 KB Output is correct
6 Correct 1 ms 332 KB Output is correct
7 Correct 1 ms 340 KB Output is correct
8 Correct 0 ms 332 KB Output is correct
9 Correct 0 ms 332 KB Output is correct
10 Correct 0 ms 332 KB Output is correct
11 Correct 1 ms 332 KB Output is correct
12 Correct 1 ms 332 KB Output is correct
13 Correct 1 ms 332 KB Output is correct
14 Correct 1 ms 332 KB Output is correct
15 Correct 1 ms 332 KB Output is correct
16 Correct 1 ms 332 KB Output is correct
17 Correct 1 ms 332 KB Output is correct
18 Correct 1 ms 336 KB Output is correct
19 Correct 1 ms 332 KB Output is correct
20 Correct 1 ms 332 KB Output is correct
21 Correct 2 ms 348 KB Output is correct
22 Correct 2 ms 468 KB Output is correct
23 Correct 3 ms 716 KB Output is correct
24 Correct 3 ms 728 KB Output is correct
25 Correct 2 ms 588 KB Output is correct
26 Correct 5 ms 972 KB Output is correct
27 Correct 5 ms 980 KB Output is correct
28 Correct 24 ms 3536 KB Output is correct
29 Correct 26 ms 3892 KB Output is correct
30 Incorrect 52 ms 7624 KB Output isn't correct
31 Halted 0 ms 0 KB -