1 solutions

  • 0
    @ 2024-12-5 18:24:10

    C++ :

    #include<iostream>
    #include<algorithm>
    #include<cstdio>
    #include<queue>
    using namespace std;
    struct node
    {
        int lo,tot,from;
    };
    struct ddd
    {
        int si,vi;
    };
    ddd data[100009];
    node p[100009];
    int flag[100009];
    bool operator <(const node& a,const node& b)
    {
        return a.tot<b.tot;
    };
    priority_queue<node> q;
    bool cmp(ddd a,ddd b)
    {
        return a.si<b.si;
    }
    int main()
    {
        int m;
        scanf("%d",&m);
        int num=m;
        for(int i=1;i<=m;i++)
            scanf("%d",&data[i].si);
        for(int i=1;i<=m;i++)
            scanf("%d",&data[i].vi);
        sort(data+1,data+1+m,cmp);
        int maxx=0;int maxj;
        for(int i=1;i<=m;i++)
        {
            if(data[i].si*2+data[i].vi>maxx)
            {
                maxx=data[i].si*2+data[i].vi;
                maxj=i;
            }
        }
        for(int i=1;i<=m;i++)
        {
            p[i].lo=i;
            p[i].tot=data[i].vi;
        }
        p[maxj].from=maxj;
        q.push(p[maxj]);
        int most=0;
        int now=maxj;
        int tot=0;
        while(m--)
        {
            node k=q.top();
            q.pop();
            if(k.from!=maxj&&k.from!=-1)continue;
            else 
            {
                if(flag[k.lo]==1)continue;
                flag[k.lo]=1;
                if(k.from==-1)
                {
                    tot+=k.tot;
                    printf("%d\n",tot);
                }
                else 
                {
                    tot+=(data[k.lo].si-data[most].si)*2+data[k.lo].vi;
                    for(int i=most+1;i<=k.lo-1;i++)
                        {
                            node l;
                            l.lo=i;
                            l.tot=data[i].vi;
                            l.from=-1;
                            q.push(l);
                        }
                        most=k.lo;
                        for(int i=most+1;i<=num;i++)
                        {
                        node l;
                        l.lo=i;
                        l.tot=data[i].vi;
                        l.from=most;
                        q.push(l);
                    }
                    cout<<tot<<endl;
                }
            }
        }
        return 0;
    } 
    
    
    • 1

    Information

    ID
    9196
    Time
    1000ms
    Memory
    128MiB
    Difficulty
    (None)
    Tags
    # Submissions
    0
    Accepted
    0
    Uploaded By