Codeforces 798D. Mike and distribution

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!

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

题意简述

给出两个大小为 $n$ 序列 $A$、$B$,从 $1~n$ 个数中选择 $k$ 个数 $p_1 \cdots p_k$,要求 $k\le \lfloor{\frac{n}{2}}\rfloor+1$,且 $2\cdot \sum_{i=1}^{k} A_{p_i} \ge \sum_{i=1}^{n} A_i$、$2\cdot \sum_{i=1}^{k} B_{p_i} \ge \sum_{i=1}^{n} B_i$。

分析

好久没做 codeforces,感觉脑洞变小了很多……

一开始想排完序,然后用数据结构维护一下,贪心地选第二维,结果这样不一定能找出解……

最后的做法是,按 $A$ 排完序就在相邻的两个选取中 $B$ 大的。这样对于序列 $B$ 一定满足,然后我们再做一些调整,如果是 $n$ 是奇数,就先把 $A$ 最大的一个拿出来,如果是偶数,就先把 $A$ 最大的两个拿出来,在最坏情况下(即相邻两个之间都选 A 小的),假设选取用 1 表示,不选取用 0 表示,那么序列可以表示为 1101010101……01,可以进行一下划分,就成了 1(10)(10)……(10)1,这样就变成相邻两个都选大的,剩下头尾两个都选,就可以满足序列 $A$ 了。

 

发表评论