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 n each 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
Input
58 7 4 8 34 2 5 3 7
Output
3 1 4 5

  题目大意 给定两个长度为n的数列,选出不多于$\left \lfloor \frac{n}{2} \right \rfloor + 1$个互不相同的下标,使得每个数组对应下标的数的和的两倍超过它的和。

  显然贪心,我有很多稀奇古怪的想法,然后全都完美Wrong Answer。突然觉得自己可能一直用的都是假贪心,给这道题跪了。下面说正解吧。

  这个可以看成二维贪心,对于高维问题我们通常想到的是降维,再根据常用套路,降维通常用的两种方法:排序和枚举一维。

  因为这里是贪心,所以显然排序。

  题目要求还可以转化成,选择一些下标,在每个数组中,被选择数之和比剩下的数的和大。

  首先选择A[1],然后之后每两个分为一组,每组中哪个对应的B大就选哪个。如果n为偶数,再把最后一个选上。

  显然在B数组中是满足题目要求的(每组中都选了最大的,还多选了1个或2个),对于A数组,每个选择了A[i]一定大于等于下一组内选择的A[j],而且会多选1个或2个,所以A数组也满足。

Code

 /**
  * Codeforces
  * Problem#798D
  * Accepted
  * Time: 62ms
  * Memory: 4500k
  */
 #include <bits/stdc++.h>
 using namespace std;
 typedef bool boolean;

 typedef class Data {
     public:
         int id;
         int x;
         int y;
 }Data;

 int n;
 int *A, *B;
 Data *ds;

 boolean cmp(const Data &a, const Data& b) {    return a.x > b.x;    }

 inline void init() {
     scanf("%d", &n);
     A = )];
     B = )];
     ds = )];
     ; i <= n; i++)
         scanf("%d", A + i), ds[i].x = A[i], ds[i].id = i;
     ; i <= n; i++)
         scanf("%d", B + i), ds[i].y = B[i];
 }

 vector<int> buf;
 inline void solve() {
     sort(ds + , ds + n + , cmp);
     buf.push_back(ds[].id);
     ; i < n; i += )
         buf.push_back((ds[i].y > ds[i + ].y) ? (ds[i].id) : (ds[i + ].id));
     ) == )
         buf.push_back(ds[n].id);
     printf("%d\n", (signed)buf.size());
     ; i < (signed)buf.size(); i++)
         printf("%d ", buf[i]);
 }

 int main() {
     init();
     solve();
     ;
 }

Codeforces 798D Mike and distribution - 贪心的更多相关文章

  1. Codeforces 798D Mike and distribution(贪心或随机化)

    题目链接 Mike and distribution 题目意思很简单,给出$a_{i}$和$b_{i}$,我们需要在这$n$个数中挑选最多$n/2+1$个,使得挑选出来的 $p_{1}$,$p_{2} ...

  2. Codeforces 798D - Mike and distribution(二维贪心、(玄学)随机排列)

    题目链接:http://codeforces.com/problemset/problem/798/D 题目大意:从长度为n的序列A和序列B中分别选出k个下表相同的数要求,设这两个序列中k个数和分别为 ...

  3. CodeForces - 798D Mike and distribution 想法题,数学证明

    题意:给你两个数列a,b,你要输出k个下标,使得这些下标对应的a的和大于整个a数列的和的1/2.同时这些下标对应的b //题解:首先将条件换一种说法,就是要取floor(n/2)+1个数使得这些数大于 ...

  4. Codeforces 798D Mike and distribution (构造)

    题目链接 http://codeforces.com/contest/798/problem/D 题解 前几天的模拟赛,居然出这种智商题..被打爆了QAQ 这个的话,考虑只有一个序列怎么做,把所有的排 ...

  5. Codeforces 798D Mike and distribution

    题目链接 题目大意 给定两个序列a,b,要求找到不多于个下标,使得对于a,b这些下标所对应数的2倍大于所有数之和. N<=100000,所有输入大于0,保证有解. 因为明确的暗示,所以一定找个. ...

  6. 【算法系列学习】codeforces D. Mike and distribution 二维贪心

    http://codeforces.com/contest/798/problem/D http://blog.csdn.net/yasola/article/details/70477816 对于二 ...

  7. CF798D Mike and distribution 贪心

    我感觉这道题挺神的~ 假设 $a[i]=b[i]$,那么我们可以将 $a$ 降序排序,然后你发现只要你按照 $1,3,5......n$ 这么取一定是合法的. 而我们发现 $2$ 比取 $3$ 优,取 ...

  8. codeforces 798 D. Mike and distribution

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

  9. [CF798D]Mike and distribution_贪心

    Mike and distribution 题目链接:http://codeforces.com/problemset/problem/798/D 数据范围:略. 题解: 太难了吧这个题..... 这 ...

随机推荐

  1. cocos2d JS-(JavaScript) 几种循环遍历对象的比较

    通常我们会用循环的方式来遍历数组.但是循环是 导致js 性能问题的原因之一.一般我们会采用下几种方式来进行数组的遍历: 方式1: for in 循环: var arr = [1,2,3,4,5]; v ...

  2. Hadoopif.for.while 语句

    if 语句 echo 当前参数个数:$# if [ $# -lt 3 ];then echo 参数小于3;elif [ $# -gt 5 ];then echo 参数大于5;fi; To have b ...

  3. 连接mysql && ERROR 2003 (HY000): Can't connect to MySQL server on 'localhost' (10061)

    上一篇:mysql服务正在启动 mysql服务无法启动 && mysql启动脚本 mysql关闭脚本 此篇目编写一个核心目的: 1.mysql连接 先抛出一个问题 这是因为mysql服 ...

  4. 简易C# socket

    服务器 using System; using System.Net; using System.Net.Sockets; using System.Text; using System.Thread ...

  5. RDD、DataFrame、Dataset三者三者之间转换

    转化: RDD.DataFrame.Dataset三者有许多共性,有各自适用的场景常常需要在三者之间转换 DataFrame/Dataset转RDD: 这个转换很简单 val rdd1=testDF. ...

  6. 解决乱码的方法是,在执行SQL语句之前,将MySQL以下三个系统参数设置为与服务器字符集character-set-server相同的字符集

    character-set-server/default-character-set:服务器字符集,默认情况下所采用的. character-set-database:数据库字符集. characte ...

  7. linux常见运维题

    linux运维题 一.填空题 1. 在Linux 系统 中,以文件方式访问设备 . (linux下一切都是文件) 2. Linux 内核引导时,从文件/etc/fstab中读取要加载的文件系统 . ( ...

  8. django 网站的搭建(2)

    这里使用nginx+uwsgi的方法来搭建生产环境 1,pip3.5  install uwsgi 下载uwsgi ,这里就不做测试了,一般不会出错 2,将django与uwsgi连接在一起 毕竟ru ...

  9. anconda1.8+cuda9.0+cudnn7.0.5+tensorflow1.7(win10)安装

    1.下载安装cuda9.0 https://developer.nvidia.com/cuda-90-download-archive 2.下载cudnn7.0.5,下载cuda9.0的对应版本 ht ...

  10. linux小倒腾

    1.vim安装,sudo apt-get install vim-gtk,于是vim就安装好了.当然在我电脑上还出现了gvim,简单的vim配置(etc/vim/vimrc): "我的设置 ...