zoukankan      html  css  js  c++  java
  • Codeforces 798D

    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.

    Example
    input
    5
    8 7 4 8 3
    4 2 5 3 7
    output
    3
    1 4 5
    题目大意:略。
    思路提示:2*(ap1 + ... + apk)>sum(ai)==>ap1+...+apk>ai中剩下的和。
    方法:给a降序排序,b不排序。输出最大的a1的下标;然后从排好序的a2开始循环,增量为2。因为a1已经是最大的了,所以a2和a3无论选哪一个剩下的那一个都没a1大,所以选下标使b更大的那个,以此类推。。。。
    所以,选出了a和b都更大的那一半。
    代码:
    #include<iostream>
    #include<cstdio>
    #include<algorithm>
    using namespace std;
    const int N=1e5+5;
    struct node
    {
        int n,id;
    }a[N],b[N];
    bool cmp(node a,node b)
    {
        return a.n>b.n; 
    } 
    int main()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
        int n;
        cin>>n;
        for(int i=1;i<=n;i++)
        cin>>a[i].n,a[i].id=i;
        for(int i=1;i<=n;i++)
        cin>>b[i].n,b[i].id=i;
        sort(a+1,a+n+1,cmp);
        cout<<n/2+1<<endl<<a[1].id;
        for(int i=2;i<=n;i+=2)
        {
            if(i<n)
            {
                if(b[a[i].id].n>=b[a[i+1].id].n)cout<<' '<<a[i].id;
                else cout<<' '<<a[i+1].id; 
            }
            else cout<<' '<<a[i].id;
        }
        cout<<endl;
        return 0;
    }
     
  • 相关阅读:
    Mysql Error Code: 1175. You are using safe update mode and you tried to update a table without a WHERE that uses a KEY column To disable safe mode
    vs2012+ winform+.net4.0发布如何在xp上运行
    ubuntu下手动配置apache2.4.12
    mysql连接错误解决(ERROR 2049 (HY000): Connection using old (pre-4.1.1) authentication protocol ref used (client option 'secure_auth' enabled))
    位运算取绝对值
    位运算两数交换
    java mysql prepareStatement模糊查询like使用注意
    idea14远程调试linux下的tomcat
    web视频播放插件:Video For Everybody
    cmd杀死进程
  • 原文地址:https://www.cnblogs.com/widsom/p/6752839.html
Copyright © 2011-2022 走看看