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. 1-微信小程序开发(安装软件和运行第一个微信小程序)

    https://developers.weixin.qq.com/miniprogram/dev/ 我的 打开 上传成功后

  2. token令牌

    本文摘自 WebApi安全性 使用TOKEN+签名验证 首先问大家一个问题,你在写开放的API接口时是如何保证数据的安全性的?先来看看有哪些安全性问题在开放的api接口中,我们通过http Post或 ...

  3. 代码无错就是优?简单工厂模式 C#

    还是那几句话: 学无止境,精益求精 十年河东,十年河西,莫欺少年穷 学历代表你的过去,能力代表你的现在,学习代表你的将来 废话不多说,直接进入正题: 现在给你一道面试题,如下: 请用C++,C#,Ja ...

  4. CRC---循环冗余校验

    typedef unsigned char uchar; typedef unsigned int uint; typedef unsigned short uInt16; uint crc; // ...

  5. 理解标准盒模型和怪异模式&box-sizing属性

    盒子模型 主要有两种,w3c标准盒模型,IE下的怪异盒模型,其实还有就是弹性盒模型(上篇文章我们用他很好的解决了对齐问题) DTD规范 盒模型分为:标准w3c盒模型.IE盒模型.以及css中的伸缩盒模 ...

  6. ant+Jacoco 统计tomcat远程部署后项目接口自动化测试或者功能测试代码覆盖率

    1.安装ant 环境,https://ant.apache.org/bindownload.cgi 2.下载jacoco包  https://www.eclemma.org/jacoco/ ,解压后, ...

  7. linux下expect环境安装以及简单脚本测试

    expect是交互性很强的脚本语言,可以帮助运维人员实现批量管理成千上百台服务器操作,是一款很实用的批量部署工具!expect依赖于tcl,而linux系统里一般不自带安装tcl,所以需要手动安装 下 ...

  8. required: true,el-upload :action="UploadUrl()"

    <el-form-item label="所属班级:" prop="Name" :rules="[{ required: true, messa ...

  9. 软件工程附加篇章:进阶四则运算和Core对接

    0x01 :计算模块(Core)和前端对接 首先特别结对编程刘乾组(SivilTaram)提供的计算模块(Core),http://www.cnblogs.com/SivilTaram/p/48599 ...

  10. 第八周--Linux中进程调度与进程切换的过程

    [潘恒 原创作品转载请注明出处 <Linux内核分析>MOOC课程 "http://mooc.study.163.com/course/USTC 1000029000 " ...