题解:先按A从大到小排序
如果n是奇数 就先把第一个选进去 然后两个两个的for 对于相邻的两个 选取B大的那个
然后就能保证a的和大于序列和的一半 因为a1>max(a2,a3) min(a2,a3)>max(a4,a5)...
b选的也是大的 所以也能保证
如果n是偶数 先这样做一次 然后把1或者2再扔进去即可
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
struct node{
int a,b,lab;
bool operator <(const node& c)const{
if(a==c.a)return b>c.b;
return a>c.a;
}
}e[100005];
vector<int>sp;
int main(){
int n,i,j;
scanf("%d",&n);
for(i=1;i<=n;i++){
scanf("%d",&e[i].a);
e[i].lab=i;
}
for(i=1;i<=n;i++)scanf("%d",&e[i].b);
sort(e+1,e+1+n);
if(n%2){
sp.push_back(e[1].lab);
i=2;
}
else i=1;
for(;i<=n;i+=2){
if(e[i].b<e[i+1].b)sp.push_back(e[i+1].lab);
else sp.push_back(e[i].lab);
}
if(n%2==0){
if(sp[0]!=e[1].lab)sp.push_back(e[1].lab);
else sp.push_back(e[2].lab);
}
printf("%d\n",sp.size());
for(i=0;i<sp.size();i++)printf("%d ",sp[i]);
printf("\n");
return 0;
}