zoukankan      html  css  js  c++  java
  • #410div2D. Mike and distribution

    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] 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.

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 typedef long long ll;
     4 #define N 100009
     5 struct node{
     6     int index,num;
     7 }a[N],b[N];
     8 int c[N],k;
     9 int  n;
    10 bool cmp(node a,node b){
    11     return a.num>b.num;
    12 } 
    13 int main(){
    14     cin>>n;
    15     for(int i=0;i<n;i++){
    16         cin>>a[i].num;
    17         a[i].index=i+1;
    18     }
    19     for(int i=0;i<n;i++){
    20         cin>>b[i].num;
    21         b[i].index=i+1;
    22     }
    23     sort(a,a+n,cmp);
    24     c[k++]=a[0].index;
    25     for(int i=1;i<n;i+=2){
    26         if(b[a[i].index-1].num>=b[a[i+1].index-1].num){
    27             c[k++]=b[a[i].index-1].index;
    28         }else{
    29             c[k++]=b[a[i+1].index-1].index;
    30         }
    31     }
    32     printf("%d
    ",k);
    33     for(int i=0;i<k;i++){
    34         printf("%d ",c[i]);
    35     }
    36 }
  • 相关阅读:
    MongoDB:数据库管理
    MongoDB:用户管理
    MongoDB:入门
    彻底透析SpringBoot jar可执行原理
    轻松了解Spring中的控制反转和依赖注入(一)
    领域驱动最佳实践--用代码来告诉你来如何进行领域驱动设计
    血的教训--如何正确使用线程池submit和execute方法
    领域驱动设计之实战权限系统微服务
    为什么我们需要领域驱动设计
    【Go入门学习】golang自定义路由控制实现(二)-流式注册接口以及支持RESTFUL
  • 原文地址:https://www.cnblogs.com/elpsycongroo/p/6761551.html
Copyright © 2011-2022 走看看