Mike has always been thinking about the harshness of social inequality. He's so obsessed with it that sometimes it even affects him while solving problems. At the moment, Mike has two sequences of positive integers A = [a1, a2, ..., an] and B = [b1, b2, ..., bn] of length neach which he uses to ask people some quite peculiar questions.
To test you on how good are you at spotting inequality in life, he wants you to find an "unfair" subset of the original sequence. To be more precise, he wants you to select k numbers P = [p1, p2, ..., pk] such that 1 ≤ pi ≤ n for 1 ≤ i ≤ k and elements in P are distinct. Sequence P will represent indices of elements that you'll select from both sequences. He calls such a subset P "unfair" if and only if the following conditions are satisfied: 2·(ap1 + ... + apk) is greater than the sum of all elements from sequence A, and 2·(bp1 + ... + bpk) is greater than the sum of all elements from the sequence B. Also, k should be smaller or equal to because it will be to easy to find sequence P if he allowed you to select too many elements!
Mike guarantees you that a solution will always exist given the conditions described above, so please help him satisfy his curiosity!
The first line contains integer n (1 ≤ n ≤ 105) — the number of elements in the sequences.
On the second line there are n space-separated integers a1, ..., an (1 ≤ ai ≤ 109) — elements of sequence A.
On the third line there are also n space-separated integers b1, ..., bn (1 ≤ bi ≤ 109) — elements of sequence B.
On the first line output an integer k which represents the size of the found subset. k should be less or equal to .
On the next line print k integers p1, p2, ..., pk (1 ≤ pi ≤ n) — the elements of sequence P. You can print the numbers in any order you want. Elements in sequence P should be distinct.
5
8 7 4 8 3
4 2 5 3 7
3
1 4 5
题意:找出【n/2】+1个序号要求2*ai>总和,2*bi>总和
题解:完全就是一水题,不过脑洞太大了,刚开始以为是把a,b加起来求和排序,结果wa了。。先给a排序,找最大的那一个,然后向后每两个找b大的那一个。证明略。
#include<map> #include<set> #include<cmath> #include<queue> #include<stack> #include<vector> #include<cstdio> #include<cstdlib> #include<cstring> #include<iostream> #include<algorithm> #define pi acos(-1) #define ll long long #define mod 1000000007 using namespace std; const int N=100000+5,maxn=100000+5,inf=0x3f3f3f3f; struct edge{ int id,av,bv,v; }e[N]; bool comp(const edge &a,const edge &b) { if(a.av!=b.av)return a.av>b.av; return a.bv>b.bv; } int main() { ios::sync_with_stdio(false); cin.tie(0); int n; cin>>n; for(int i=1;i<=n;i++) { cin>>e[i].av; e[i].id=i; } for(int i=1;i<=n;i++) { cin>>e[i].bv; e[i].v=e[i].av+e[i].bv; } sort(e+1,e+n+1,comp); cout<<n/2+1<<endl<<e[1].id<<" "; for(int i=2;i<=n;i+=2) { if(i+1<=n) { if(e[i].bv>=e[i+1].bv)cout<<e[i].id<<" "; else cout<<e[i+1].id<<" "; } else cout<<e[i].id<<" "; } return 0; }