답안 #883427

# 제출 시각 아이디 문제 언어 결과 실행 시간 메모리
883427 2023-12-05T09:16:11 Z alexdd 금 캐기 (IZhO14_divide) C++17
0 / 100
1 ms 4444 KB
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int INF = 1e18;
int n;
int x[100005];
int g[100005];
int d[100005];
int prefd[100005];
int prefg[100005];
map<int,int> mp;
map<int,int> nrm;
int cate=0;
int aint[800005];
void build(int nod, int st, int dr)
{
    aint[nod]=-INF;
    if(st==dr)
        return;
    int mij=(st+dr)/2;
    build(nod*2,st,mij);
    build(nod*2+1,mij+1,dr);
}
void upd(int nod, int st, int dr, int poz, int newv)
{
    if(st==dr)
    {
        aint[nod] = max(aint[nod],newv);
        return;
    }
    int mij=(st+dr)/2;
    if(poz<=mij) upd(nod*2,st,mij,poz,newv);
    else upd(nod*2+1,mij+1,dr,poz,newv);
    aint[nod] = max(aint[nod*2], aint[nod*2+1]);
}
int qry(int nod, int st, int dr, int le, int ri)
{
    if(le>ri)
        return -INF;
    if(le==st && dr==ri)
        return aint[nod];
    int mij=(st+dr)/2;
    return max(qry(nod*2,st,mij,le,min(mij,ri)),
                qry(nod*2+1,mij+1,dr,max(mij+1,le),ri));
}
signed main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>x[i]>>g[i]>>d[i];
        prefd[i] = prefd[i-1] + d[i];
        prefg[i] = prefg[i-1] + g[i];
        mp[x[i]-prefd[i]]++;
        mp[x[i]-prefd[i-1]]++;
    }
    mp[0]++;
    for(auto it:mp)
    {
        if(it.second==0)
            continue;
        nrm[it.first]=++cate;
    }
    build(1,1,cate);
    int mxm=0;
    for(int i=1;i<=n;i++)
    {
        upd(1,1,cate,nrm[x[i]-prefd[i-1]],-g[i]);
        mxm = max(mxm, g[i]+qry(1,1,cate,nrm[x[i]-prefd[i]],cate));
    }
    cout<<mxm;
    return 0;
}
/**
 
prefd[ri] - prefd[le-1] >= x[ri] - x[le]
prefd[ri] - x[ri] >= prefd[le-1] - x[le]
 
*/
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -
# 결과 실행 시간 메모리 Grader output
1 Incorrect 1 ms 4444 KB Output isn't correct
2 Halted 0 ms 0 KB -