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] andB = [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 Pare 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

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] andB = [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 Pare 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
5
8 7 4 8 3
4 2 5 3 7
output
3
1 4 5

解题思路:

这道题题意有点难描述,而且不难看懂就不多说了。

这道题难点就在于有两个数组,难以判断。 所以我们这里先讨论只有一个数组时的情况,如何使取得的数字大于剩下的?其实只要两两之间相互比较,取最大的,当序列长度为奇数时,我们可以先提出

其中一个,然后将剩余的两两比较,依旧必大于剩余的。

单个数组的问题讨论完了,然后分析两个数组,这里我们可以将其中一个数组排序用另一个数组记录排序结果(下标)id[],对下一个数组进行排序,这么说有点抽象,我把具体实现情况写一下

a[0] = 8 ,a[1] = 7,a[2] = 4, a[3] = 8,a[4] = 3;

b[0] = 4,a[1] = 2,a[2] = 5, a[3] = 3,a[4] = 7;

id[0] = 0,id[1] = 1,id[2] = 2,id[3] = 3,id[4] = 4;

先将a数组排序从大到小并用id数组记录结果(下标)

a数组排序结果 :  a0 a3 a1 a2 a4

用id数组记录:id[0] = 0,id[1] = 3,id[2] = 1,id[3] = 2,id[4] = 4;

这里可以用id对b数组进行排序,因为现在id储存的是a从大到小的顺序,按这个顺序排序a必大于剩余的,

排序过程: 因为是奇数,先取出第一个 b[0] 然后取 max(b[3],b[1]),max(b[2],b[4]),这样就可以得出满足两个数组的下标序列

实现代码:

#include<bits/stdc++.h>
using namespace std;
const int Max = +;
int m,id[Max];
long long a[Max],b[Max];
inline bool cmp(const int &x,const int &y)
{
return a[x] > a[y];
}
int main()
{
int i;
cin>>m;
for(i=;i<m;i++) cin>>a[i];
for(i=;i<m;i++) cin>>b[i];
for(i=;i<m;i++) id[i] = i;
sort(id,id+m,cmp);
int n = m/ + ;
cout<<n<<endl;
cout<<id[]+;
for(i=;i<m-;i+=){
if(b[id[i]]>b[id[i+]])
cout<<" "<<id[i]+;
else
cout<<" "<<id[i+]+;
}
if(m%==)
cout<<" "<<id[m-]+;
cout<<endl;
return ;
}

codeforces 798 D. Mike and distribution的更多相关文章

  1. codeforces 798 D. Mike and distribution(贪心+思维)

    题目链接:http://codeforces.com/contest/798/problem/D 题意:给出两串长度为n的数组a,b,然后要求长度小于等于n/2+1的p数组是的以p为下表a1-ap的和 ...

  2. codeforces 798 C. Mike and gcd problem(贪心+思维+数论)

    题目链接:http://codeforces.com/contest/798/problem/C 题意:给出一串数字,问如果这串数字的gcd大于1,如果不是那么有这样的操作,删除ai, ai + 1 ...

  3. 【codeforces 798D】Mike and distribution

    [题目链接]:http://codeforces.com/contest/798/problem/D [题意] 让你选一个下标集合 p1,p2,p3..pk 使得2*(a[p1]+a[p2]+..+a ...

  4. Codeforces 798 B. Mike and strings-String的find()函数

    好久好久好久之前的一个题,今天翻cf,发现这个题没过,补一下. B. Mike and strings time limit per test 2 seconds memory limit per t ...

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

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

  6. D. Mike and distribution 首先学习了一个玄学的东西

    http://codeforces.com/contest/798/problem/D D. Mike and distribution time limit per test 2 seconds m ...

  7. CF410div2 D. Mike and distribution

    /* CF410div2 D. Mike and distribution http://codeforces.com/contest/798/problem/D 构造 题意:给出两个数列a,b,求选 ...

  8. #410div2D. Mike and distribution

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

  9. Codeforces 547C/548E - Mike and Foam 题解

    目录 Codeforces 547C/548E - Mike and Foam 题解 前置芝士 - 容斥原理 题意 想法(口胡) 做法 程序 感谢 Codeforces 547C/548E - Mik ...

随机推荐

  1. 一篇自己都看不懂的Matrix tree总结

    Matrix tree定理用于连通图生成树计数,由于博主太菜看不懂定理证明,所以本篇博客不提供\(Matrix\ tree\)定理的证明内容(反正这个东西背结论就可以了是吧) 理解\(Matrix\ ...

  2. NPOI导Excel样式设置

    一.创建一个Excel //创建一个工作簿 XSSFWorkbook workbook = new XSSFWorkbook(); //创建一个页 ISheet sheet = workbook.Cr ...

  3. 利用数据库触发器让字段与自增长Id相关联

    十年河东,十年河西,莫欺少年穷 学无止境,精益求精 今天是数据库脚本类的代码,所以不想过多阐述 如下数据表: create table Card( Id ,) primary key, CardNo ...

  4. 【LGR-047】洛谷5月月赛

    这次我期待了很久的Luogu月赛崩掉了 传说中的Luogu神机就这样被卡爆了 然后我过了20min才登上Luogu的网站,30min后才看到题目 然后交T1TM的不给我测!!!然后又交了一次机子就炸了 ...

  5. .Net版本依赖之坑引发的搜查

    前言 今天上午,一个客户反馈XX消息没有推送到第三方链接.于是我查看了推送日志列表,并没有今天的.接着登录服务器查询文件日志,看到了记录.我们的代码步骤是消息先推送到消息队列,消费消息队列时,记录文件 ...

  6. RabbitMQ 延时消息设计

    问题背景 所谓"延时消息"是指当消息被发送以后,并不想让消费者立即拿到消息,而是等待指定时间后,消费者才拿到这个消息进行消费. 场景一:客户A在十二点下了一个订单,我想半个小时后来 ...

  7. wordcount程序中的应用与拓展

    设计思路: 关键是思路,首先知道 单词, 行,字符, 他们有什么特点: 1.单词,标准的是遇到空格后,单词数,自动加一. 2.行是以\n结束的, 也就是说, 遇到\n行数加一,当然也视你的操作系统而言 ...

  8. VIM编辑器常用命令(转)

    转自:https://www.cnblogs.com/Nice-Boy/p/6124177.html

  9. Opentsdb 启动显示配置文件不存在

    今天 重新启动opentsdb  出现本地配置文件不存在   这不知道  我查了一下官网 了解到 You can use the --config command line argument to s ...

  10. Java实现小学四则运算练习系统(UI)

    github项目地址 :https://github.com/feser-xuan/Arithmetic_test3_UI 小伙伴的博客链接:http://www.cnblogs.com/fukang ...