题目链接:https://vjudge.net/contest/375342#problem/B
解题思路:
主要突破口是在取的数的个数上,最多可取n/2向下取整再加1个数,也就是取的数永远比剩下的数多
先按a数组有大到下排序,把a数组中最大的先取,然后再取n/2向下整个数,这向下取整个数在接下来的n/2向下取整个组中,每个组大小为2,挑取b大的就可以满足条件。
注意奇偶数最后一位的选取问题,最后一组只有一个数的时候直接选就行
#include<iostream>
#include<cstdio>
#include<string.h>
#include<algorithm>
using namespace std;
#define ll long long
struct node{
int a;
int b;
int pos;
}c[110000];
int n,m;
bool cmp(node t1,node t2)
{
return t1.a==t2.a?(t1.b>t2.b):(t1.a>t2.a);
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++) scanf("%d",&c[i].a),c[i].pos=i;
for(int i=1;i<=n;i++) scanf("%d",&c[i].b);
sort(c+1,c+1+n,cmp);
printf("%d\n",n/2+1);
printf("%d ",c[1].pos);
for(int i=2;i<=n;i+=2){
if(i==n){
printf("%d\n",c[i].pos);
break;
}
if(c[i].b>c[i+1].b)
printf("%d ",c[i].pos);
else printf("%d ",c[i+1].pos);
}
return 0;
}