Submission #528791

# Submission time Handle Problem Language Result Execution time Memory
528791 2022-02-21T13:21:03 Z perchuts Divide and conquer (IZhO14_divide) C++17
17 / 100
1 ms 332 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;
        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));
    // for(auto x:cmp)cout<<x<<" ";
    // cout<<endl;
    // for(int i=1;i<=n;++i)cout<<pref[i]<<" ";
    // cout<<endl;
    // S - S' >= 0  => S >= S'
    sum = v[1].e;
    int 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!=n+1&&cmp[ind-1]>sum)ind--;
        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 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 320 KB Output is correct
7 Correct 1 ms 320 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 324 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 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 320 KB Output is correct
7 Correct 1 ms 320 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 324 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 0 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 Incorrect 1 ms 332 KB Output isn't correct
18 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 332 KB Output is correct
2 Correct 0 ms 332 KB Output is correct
3 Correct 1 ms 332 KB Output is correct
4 Correct 1 ms 320 KB Output is correct
5 Correct 0 ms 332 KB Output is correct
6 Correct 0 ms 320 KB Output is correct
7 Correct 1 ms 320 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 324 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 0 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 Incorrect 1 ms 332 KB Output isn't correct
18 Halted 0 ms 0 KB -