Submission #1195014

#TimeUsernameProblemLanguageResultExecution timeMemory
1195014vneduBulldozer (JOI17_bulldozer)C++17
5 / 100
2 ms584 KiB
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;

template<class T> bool maximize(T &a, const T &b){ return (a < b ? a = b, 1 : 0); }
template<class T> bool minimize(T &a, const T &b){ return (a > b ? a = b, 1 : 0); }

#define fi first
#define se second

#define pb push_back
#define ii pair<int, int>

#define all(x) x.begin(), x.end()

#define TASK "nonsense"

/// end of template ///

#define double long double

const int N = 2e3 + 10;
const double esp=1e-9;
double inf=-(INT_MAX-10);
struct segTree
{
    struct node
    {
        ll mx,p,s,sum;
        node() {}
        node(ll val) : mx(val),p(val),s(val),sum(val) {}

        node operator * (const node &S) const
        {
            node ans;
            ans.sum=sum+S.sum;
            ans.p=max(p,sum+S.p);
            ans.s=max(S.s,S.sum+s);
            ans.mx=max({mx,S.mx,s+S.p});
            return ans;
        }
    } t[N<<2];
    segTree() {}
    void update(int id, int l, int r, int x, ll val)
    {
        if(l>x||r<x) return;
        if(l==r) return void(t[id]=node(val));
        int mid((l+r)>>1);
        update(id<<1,l,mid,x,val);
        update(id<<1|1,mid+1,r,x,val);
        t[id]=t[id<<1]*t[id<<1|1];
    }
    ll get()
    {
        return t[1].mx;
    }
} segtree;
struct Point
{
    int x,y,w;
    Point() {}
    void input()
    {
        cin>>x>>y>>w;
    }
    double slope(const Point &S) const
    {
        return (y-S.y)*1.0/(x-S.x);
    }
    bool operator < (const Point &S) const
    {
        return x<S.x;
    }
} point[N];
struct Slope
{
    double slope;
    int i,j;
    Slope() {}
    Slope(double slope, int i, int j ) : slope(slope),i(i),j(j) {}
    bool operator < (const Slope &S) const
    {
        return slope<S.slope;
    }
} s[N*N/2];
int n,ptr=0,pos[N],g[N],b[N];
bool cmp(int i, int j)
{
    return point[i].y-inf*point[i].x<point[j].y-inf*point[j].x;
}
void print(double val)
{
    cout<<fixed<<' '<<setprecision(10)<<val<<'\n';
}
set<pair<double,int>> mp;
void solve()
{
    cin>>n;
    for(int i=1;i<=n;++i) point[i].input();
    sort(point+1,point+1+n);
    ll ans=0,sum=0;
    for(int i=1;i<=n;)
    {
        int val=point[i].x;
        ll cur=0;
        while(i<=n && point[i].x==val)
        {
            cur+=point[i].w;
            ++i;
        }
        sum=max(0LL,sum)+cur;
        maximize(ans,sum);
    }
//    for(int i=1;i<=n;++i) cout<<point[i].x<<' '<<point[i].y<<' '<<point[i].w<<'\n';
    for(int i=1;i<=n;++i) for(int j=1;j<=n;++j) if(i!=j && point[i].x>point[j].x) s[++ptr]=Slope(point[i].slope(point[j]),i,j);
//    cout<<ptr;
//    return;
    sort(s+1,s+1+ptr);
    for(int i=1;i<=n;++i) g[i]=i;
    sort(g+1,g+1+n,cmp);
//    for(int i=1;i<=n;++i) cout<<g[i]<<' ';
//    return;
    for(int i=1;i<=n;++i)
    {
        pos[g[i]]=i;
        segtree.update(1,1,n,i,point[g[i]].w);
    }
//    for(int i=1;i<=n;++i) cout<<g[i]<<' ';
//    cout<<'\n';
    maximize(ans,segtree.get());
//    cout<<ptr<<'\n';
    for(int i=1;i<=ptr;)
    {
        double val=s[i].slope;
        set<pair<double,int>>().swap(mp);
//        print(val);
        while(i<=ptr && abs(s[i].slope-val)<esp)
        {
//            cout<<s[i].i<<' '<<s[i].j<<'\n';
            int id=s[i].i;
            double slope=point[id].y-val*point[id].x;
//            int id2=s[i].j;
//            double slope2=point[id2].y-val*point[id2].x;
//            if(abs(slope-slope2)>=1e-9) cout<<"DSA";
//            if(slope!=slope2)
//            {
//                print(slope);
//                print(slope2);
////                cout<<(slope==slope2?"AC\n":"NO\n");
////                if(abs(slope-slope2)<1e-15) cout<<"AC\n";
////                else cout<<"WA\n";
//                cout<<fixed<<setprecision(30)<<abs(slope-slope2)<<'\n';
//                cout<<'\n';
//            }
            mp.insert({slope,pos[s[i].i]});
            mp.insert({slope,pos[s[i].j]});
//            cout<<s[i].i<<' '<<s[i].j<<'\n';
            ++i;
        }

//        int cnt=0;
        for(auto it=mp.begin(); it!=mp.end(); )
        {
            int l=INT_MAX,r=INT_MIN;
            double nval=(*it).fi;
//            ++cnt;
//            while(it!=mp.end() && (*it).fi==nval) ++r,++it;
            while(it!=mp.end() && abs((*it).fi-nval)<esp)
            {
//                if(r+1!=(*it).se) cout<<fixed<<setprecision(3)<<nval<<'\n';
                minimize(l,(*it).se);
                maximize(r,(*it).se);
                ++it;
            }
//            cout<<l<<' '<<r<<'\n';
//            if(r>n||r<1||l>n||l<1||l>r) return void(cout<<1/0);
            for(int j=l;j<=r;++j)
            {
                b[j]=g[r-j+l];
            }
            for(int j=l;j<=r;++j)
            {
                swap(b[j],g[j]);
                segtree.update(1,1,n,j,point[g[j]].w);
                pos[g[j]]=j;
            }
//            cout<<l<<' '<<r<<'\n';
        }
//        for(int i=1;i<=n;++i) b[i]=i;
//        inf=val+1e-6;
//        sort(b+1,b+1+n,cmp);
//        for(int i=1;i<=n;++i) cout<<b[i]<<' ';
//        cout<<'\n';
//        for(int i=1;i<=n;++i) cout<<g[i]<<' ';
//        cout<<'\n'<<'\n';
//        for(int i=1;i<=n;++i) if(b[i]!=g[i]) return void(cout<<1/0);
//        cout<<"DSA";
//        bool ok=0;
//        for(int i=1;i<=n;++i) if(b[i]!=g[i]) ok=1;
//        if(ok)
//        {
//            for(int x : v) cout<<x<<' ';
//            cout<<'\n';
////            cout<<i<<' '<<cnt<<'\n';
//            for(int i=1;i<=n;++i) cout<<b[i]<<' ';
//            cout<<'\n';
//            for(int i=1;i<=n;++i) cout<<g[i]<<' ';
//            cout<<'\n'<<'\n';
//        }
//        cout<<'\n';
//        for(int i=1;i<=n;++i) cout<<g[i]<<' ';
//        cout<<'\n';
//        cout<<'\n';
        maximize(ans,segtree.get());
    }
    cout<<ans;
}

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

//    freopen(TASK".inp","r",stdin);
//    freopen(TASK".out","w",stdout);

    int testcase=1;
//    cin>>testcase;

    while (testcase--)
        solve();

    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...