CF798D:Mike and distribution(思维 )^

来源:互联网 发布:文本压缩算法 编辑:程序博客网 时间:2024/06/06 02:05

D. Mike and distribution
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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 greaterthan 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!

Input

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.

Output

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.

Example
input
58 7 4 8 34 2 5 3 7
output
31 4 5

题意:给两个N个元素的数组,最多选择K=N/2+1个不同下标,使得各自两个数组中这些下标的元素之和*2>各自数组的元素总和。

思路:即求取K个元素之和大于剩下的元素之和,按A排序,两个两个地按B选择。

# include <bits/stdc++.h>using namespace std;int a[1<<20], b[1<<20], c[1<<20], d[1<<20];int main(){    int n, cnt=0;    scanf("%d",&n);    for(int i=0; i<n; ++i) scanf("%d",&a[i]);    for(int i=0; i<n; ++i) scanf("%d",&b[i]);    for(int i=0; i<n; ++i) c[i] = i;    sort(c, c+n, [&](int x, int y){return a[x] > a[y];});    d[cnt++] = c[0];    for(int i=1; i<n; i+=2)    {        int t = c[i];        if(i+1<n && b[c[i+1]] > b[t])            t = c[i+1];        d[cnt++] = t;    }    printf("%d\n",cnt);    for(int i=0; i<cnt; ++i) printf("%d ",d[i]+1);    return 0;}


原创粉丝点击