• CodeForces Round #521 (Div.3) E. Thematic Contests


    http://codeforces.com/contest/1077/problem/E

    output
    standard output

    Polycarp has prepared nn competitive programming problems. The topic of the ii-th problem is aiai, and some problems' topics may coincide.

    Polycarp has to host several thematic contests. All problems in each contest should have the same topic, and all contests should have pairwise distinct topics. He may not use all the problems. It is possible that there are no contests for some topics.

    Polycarp wants to host competitions on consecutive days, one contest per day. Polycarp wants to host a set of contests in such a way that:

    • number of problems in each contest is exactly twice as much as in the previous contest (one day ago), the first contest can contain arbitrary number of problems;
    • the total number of problems in all the contests should be maximized.

    Your task is to calculate the maximum number of problems in the set of thematic contests. Note, that you should not maximize the number of contests.

    Input

    The first line of the input contains one integer nn (1n21051≤n≤2⋅105) — the number of problems Polycarp has prepared.

    The second line of the input contains nn integers a1,a2,,ana1,a2,…,an (1ai1091≤ai≤109) where aiai is the topic of the ii-th problem.

    Output

    Print one integer — the maximum number of problems in the set of thematic contests.

    Examples
    input
    Copy
    18
    2 1 2 10 2 10 10 2 2 1 10 10 10 10 1 1 10 10
    
    output
    Copy
    14
    
    input
    Copy
    10
    6 6 6 3 6 1000000000 3 3 6 6
    
    output
    Copy
    9
    
    input
    Copy
    3
    1337 1337 1337
    
    output
    Copy
    3
    
    Note

    In the first example the optimal sequence of contests is: 22 problems of the topic 11, 44 problems of the topic 22, 88 problems of the topic 1010.

    In the second example the optimal sequence of contests is: 33 problems of the topic 33, 66 problems of the topic 66.

    In the third example you can take all the problems with the topic 13371337 (the number of such problems is 33 so the answer is 33) and host a single contest.

    代码:

        #include <bits/stdc++.h>
        using namespace std;
    
        const int maxn = 2e5 + 10;
        const int N = 1e6 + 5;
        int n;
        int a[N];
    
        int main() {
            scanf("%d", &n);
            int cnt = 0;
            map<int, int> mp;
            for(int i = 1; i <= n; i ++) {
                int x;
                scanf("%d", &x);
                if(!mp[x]) {
                    cnt ++;
                    mp[x] = cnt;
                }
                a[mp[x]] ++;
            }
            sort(a + 1, a + 1 + cnt);
            int ans = 0;
    
            for(int i = 1; i <= n; i ++) {
                int st = 1;
                int m = 0;
                for(int k = i; k <= n; k *= 2) {
                    int pos = lower_bound(a + st, a + 1 + cnt, k) - a;
                    if(pos == cnt + 1) break;
                    m += k;
                    st = pos + 1;
                }
                ans = max(ans, m);
            }
            printf("%d
    ", ans);
            return 0;
        }
    

      

  • 相关阅读:
    ORACLE【0】:基本操作
    ORACLE【3】:分区表以及分区索引
    ORACLE【2】:锁机制及解锁
    log4j学习一:解决系统日志错位问题
    使用一个非堵塞的socket用于接收http请求
    Python中文转换报错 'ascii' codec can't decode byte 0xe8 in position
    首次使用Redis记录【3】
    xsi:schemaLocation有何作用
    【转】【redis】3.Spring 集成注解 redis 项目配置使用
    maven仓库地址
  • 原文地址:https://www.cnblogs.com/zlrrrr/p/10085595.html
Copyright © 2020-2023  润新知