Submission #113760

#TimeUsernameProblemLanguageResultExecution timeMemory
113760DiuvenBulldozer (JOI17_bulldozer)C++14
100 / 100
1450 ms48092 KiB
#include <bits/stdc++.h>
using namespace std;

typedef long long lint;
typedef pair<int, int> pii;

const int MAX = 2019;

int n, X[MAX], Y[MAX], V[MAX];

inline lint _max(lint a, lint b){ return a<b ? b : a; }

class Seg_t{
	struct node {
		lint ls, rs, ms, su;
		node operator + (const node &op) const {
			node res = {0,0,0,0};
			// ls, rs should not be empty.
			// ms may be empty
			res.ls = _max(ls, su+op.ls);
			res.rs = _max(op.rs, op.su+rs);
			res.ms = _max(rs+op.ls, _max(ms, op.ms));
			res.su = su + op.su;
			return res;
		}
    } T[4096];
	void upt(int v, int s, int e, int p, int x){
		if(s==e){ T[v]={x,x,_max(0,x),x}; return; }
        int mid = (s+e)/2;
        if(p<=mid) upt(v*2,s,(s+e)/2,p,x);
        else upt(v*2+1,(s+e)/2+1,e,p,x);
		T[v] = T[v*2]+T[v*2+1];
	}
  public:
    void upt(int p, int x){ upt(1,1,n,p,x); }
	lint get(){ return T[1].ms; }
} Seg;

int nu[MAX], re[MAX];
void ch(int a, int b){
	int i=re[a], j=re[b];
	Seg.upt(i, V[b]), Seg.upt(j, V[a]);
	swap(nu[i], nu[j]); swap(re[a], re[b]);
}
pii D[MAX][MAX];

int cmp(pii a, pii b){
    int u,v, s,t; tie(u,v)=a, tie(s,t)=b;
    pii l1=D[a.first][a.second], l2=D[b.first][b.second];
    lint w = 1LL*l1.second*l2.first - 1LL*l1.first*l2.second;
    return w==0 ? 0 : (w<0 ? -1 : 1);
}

int main(){
	ios::sync_with_stdio(0); cin.tie(0);

	cin>>n;
	for(int i=1; i<=n; i++) cin>>X[i]>>Y[i]>>V[i];
    int rnk[MAX], tmp[MAX];
    iota(tmp+1, tmp+n+1, 1);
    sort(tmp+1, tmp+n+1, [](int a, int b){ return pii(-X[a],Y[a]) < pii(-X[b],Y[b]); });
    for(int i=1; i<=n; i++) rnk[tmp[i]]=i;

	iota(nu+1, nu+n+1, 1);
	sort(nu+1, nu+n+1, [&](int a, int b){
        return rnk[a]>rnk[b];
	});
	for(int i=1; i<=n; i++){
		Seg.upt(i, V[nu[i]]);
		re[nu[i]]=i;
	}

    vector<pii> P;

    for(int i=1; i<=n; i++) for(int j=i+1; j<=n; j++){
        P.emplace_back(i,j);
        int dx=X[i]-X[j], dy=Y[i]-Y[j];
        if(dx<0 || (dx==0 && dy>0)) dx=-dx, dy=-dy;
        D[i][j] = D[j][i] = {dx,dy};
    }

    sort(P.begin(), P.end(), [&](pii a, pii b){
        int z = cmp(a,b);
        if(z!=0) return z<0;
        
        int u,v, t,s; tie(u,v)=a, tie(t,s)=b;
        lint dx,dy; tie(dx,dy) = D[u][v];

        lint ub = -dy*X[u] + dx*Y[u];
        lint tb = -dy*X[t] + dx*Y[t];
        if(ub!=tb) return ub<tb;

        pii p={rnk[u],rnk[v]}, q={rnk[t],rnk[s]};
        if(p.first>p.second) swap(p.first, p.second);
        if(q.first>q.second) swap(q.first, q.second);
        return p<q;
    });

	lint ans = Seg.get();

    for(int i=0; i<int(P.size());){
        pii st = P[i];
        while(i<int(P.size()) && cmp(st, P[i])==0){
            ch(P[i].first, P[i].second); i++;
        }
        ans = _max(ans, Seg.get());
    }

	cout<<ans<<'\n';

	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...