Submission #525328

# Submission time Handle Problem Language Result Execution time Memory
525328 2022-02-11T10:18:24 Z AA_Surely Divide and conquer (IZhO14_divide) C++14
0 / 100
0 ms 204 KB
#include <bits/stdc++.h>

#define FOR(i,x,n) 	for(LL i=x; i<n; i++)
#define F0R(i,n) 	FOR(i,0,n)
#define ROF(i,x,n) 	for(LL i=n-1; i>=x; i--)
#define R0F(i,n) 	ROF(i,0,n)

#define WTF 		cout << "WTF" << endl

#define IOS 		ios::sync_with_stdio(false); cin.tie(0)
#define F 			first
#define S	 		second
#define pb 			push_back

#define ALL(x) 		x.begin(), x.end()
#define RALL(x) 	x.rbegin(), x.rend()

using namespace std;
typedef long long 		LL;
typedef pair<LL, LL> 	PLL;

typedef vector<LL> 		VLL;
typedef vector<PLL> 	VPLL;

const LL MAXN = 1e5 + 7;
const LL INF = 1e18;

struct Mine {
    LL pt, gd, eg;
} ns[MAXN];

LL n;

LL solve(LL l, LL r) {
    if (l > r) return -INF;
    if (l == r) return ns[l].gd;
    LL mid = (l + r) >> 1;

    LL ret = max(solve(l, mid), solve(mid + 1, r));
    VPLL lf, rt;

    LL gsum = 0, esum = 0;
    ROF(i, l, mid + 1) {
        gsum += ns[i].gd;
        esum += ns[i].eg;

        lf.pb({esum - (ns[mid].pt - ns[i].pt), gsum});
    }
    
    gsum = 0, esum = 0;
    FOR(i, mid + 1, r + 1) {
        gsum += ns[i].gd;
        esum += ns[i].eg;

        rt.pb({esum - (ns[i].pt - ns[mid].pt), gsum});
    }

    sort(ALL(lf));
    sort(RALL(rt));
    
    LL lmx = -INF, rmx = -INF, rptr = 0;
    for(PLL on : lf) {
        LL weight = on.F, gold = on.S;
        lmx = max(lmx, (LL)gold);
        
        while(rptr < (LL)rt.size() && weight + rt[rptr].F >= 0) {
            rmx = max(rmx, rt[rptr].S);
            rptr++;
        }

        ret = max(ret, lmx + rmx);
    }

    return ret;
}

int main() {
    IOS;
    
    cin >> n;
    F0R(i, n) cin >> ns[i].pt >> ns[i].gd >> ns[i].eg;
    cout << solve(0, n - 1);
}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 204 KB Output is correct
2 Incorrect 0 ms 204 KB Output isn't correct
3 Halted 0 ms 0 KB -