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. ASP.NET Core MVC中Controller的Action,默认既支持HttpGet,又支持HttpPost

    我们知道ASP.NET Core MVC中Controller的Action上可以声明HttpGet和HttpPost特性标签,来限制可以访问Action的Http请求类型(GET.POST等). 那 ...

  2. [Oracle]OWI学习笔记--001

    [Oracle]OWI学习笔记--001 在 OWI 的概念里面,最为重要的是 等待事件 和 等待时间. 等待事件发生时,需要通过 P1,P2,P3 查看具体的资源. 可以通过 v$session_w ...

  3. [spark][python]Spark map 处理

    map 就是对一个RDD的各个元素都施加处理,得到一个新的RDD 的过程 [training@localhost ~]$ cat names.txtYear,First Name,County,Sex ...

  4. 线程池ThreadPoolExecutor整理

    项目用到线程池,但是其实很多人对原理并不熟悉 ,这里只是整理一下 ThreadPoolExecutor java.uitl.concurrent.ThreadPoolExecutor类是线程池中最核心 ...

  5. 解决Jira和Confluence访问打开越来越缓慢问题

    Jira和Confluence部署在同一台服务器上,跑一段时间后,发现访问jira和confluence时,打开越来越缓慢.这是因为根据主机物理内存不同,默认的java虚拟机内存也会不同(一个较低值) ...

  6. WinForm多线程+委托防止界面假死

    当有大量数据需要计算.显示在界面或者调用sleep函数时,容易导致界面卡死,可以采用多线程加委托的方法解决 using System; using System.Collections.Generic ...

  7. Web系统页面打印技术实现与分析

    1 Web页面打印概述应用WEB化,不论对开发商,还是对用户来说,实在是一种很经济的选择,因为基于WEB的应用,客户端的规则很简单,容易学习,容易维护,容易发布.在WEB系统中,打印的确是个烦人的问题 ...

  8. 【个人阅读】软件工程M1/M2阶段总结

    这次作业是好久以前布置的,由于学期末课程设计任务比较重,我在完善M2阶段的代码的同时又忙于数据库的实现和编译器的实现,一度感觉忙得透不过气来....到这些都基本完成的时候,会看自己以前的阅读心得,觉得 ...

  9. 软件工程驻足篇章:第十七周和BugPhobia团队漫长的道别

    0x01 :序言 I am a slow walker, but I never walk backwards. 成长于被爱,学着爱人 成长的故事 也是年少的星期六结束的故事 就仿佛我和BugPhob ...

  10. 第三个Sprint冲刺第3天

    成员:罗凯旋.罗林杰.吴伟锋.黎文衷 组内各成员加紧完成自己的工作.