F to take items

Link https://ac.nowcoder.com/acm/contest/3003/F

Coke and beef cattle before there are n items, these items are numbered 1,2, \ dots, n1,2, ..., n, each item has two attributes a_i, b_iai, bi.

 

Cola and beef cattle will take a turn from any of the remaining items, first select beef.

 

The set number of selected items is provided beef is H, bovine cola selected set item number is T, then take complete, beef has a score of \ sum_ {i \ in H} a_iΣi∈H ai; Coke and bovine score \ sum_ {i \ in T} b_iΣi∈T bi.

 

Beef and cattle cola hope that their scores as large than the other (ie, to maximize their own and each other's score difference).

 

You need to find a case where both using the optimal strategy, and ultimately will choose which items are, if multiple answers or output order, output either.

Enter a description:

The first line, a positive integer n, the number of items.
The second line, n integers a_1, a_2, \ dots, a_na1, a2, ..., an, A represents the attribute of n items.
Third row, n integers b_1, b_2, \ dots, b_nb1, b2, ..., bn, B represents the properties of n items.
保证 2 \ leq n \ leq 2 \ times 10 ^ 52≤n≤2 × 105,0 \ leq a_i, b_i \ leq 10 ^ 90≤ai, bi ≤109.

Output Description:

Two output lines, respectively, under the optimal strategy beef cattle and cola choose which items each output item number.

Example 1

Entry

copy

3
8 7 6
5 4 2

Export

copy

1 3
2

Explanation

 

3 1

2

It will also be judged to be true

Code:

#include<bits/stdc++.h>
using namespace std;
long long n,t,g,k,l,o,s,r,ans,ss,max1=0;
struct node {
    int s;
    int f;
    int id;
}a[200005],b[200005];
bool cmp(node p,node q)
{
    if(p.s+p.f!=q.s+q.f)
    return p.s+p.f>q.s+q.f;
    else if(p.s!=q.s)
    return p.s>q.s;
    else
    return p.f>q.f;
}
map<long long,long long>m;
queue<long long>aa,bb;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i].s;
        a[i].id=i;
    }
    for(int i=1;i<=n;i++)
    {
        cin>>b[i].s;
        a[i].f=b[i].s;
        b[i].id=i;
        b[i].f=a[i].s;
    }
    sort(a+1,a+1+n,cmp);
    sort(b+1,b+1+n,cmp);
    int ia=1,ib=1;
    for(int i=1;i<=n;i++)
    {
        if(i%2==1)
        {
            while(m[a[ia].id]!=0)
            {
                ia++;
            }
            aa.push(a[ia].id);
            m[a[ia].id]=1;
            ia++;
        }
        else
        {
            while(m[b[ib].id]!=0)
            {
                ib++;
            }
            bb.push(b[ib].id);
            m[b[ib].id]=1;
            ib++;
        }
    }
    while(!aa.empty())
    {
        cout<<aa.front()<<" ";
        aa.pop();
    }
    cout<<endl;
    while(!bb.empty())
    {
        cout<<bb.front()<<" ";
        bb.pop();
    }
}

 

Published 180 original articles · won praise 16 · views 10000 +

Guess you like

Origin blog.csdn.net/Luoriliming/article/details/104203585