【CodeForces 1077E --- Thematic Contests】思维+贪心

题目来源:点击进入【CodeForces 1077E — Thematic Contests】

Description

Polycarp has prepared n competitive programming problems. The topic of the i-th problem is ai, 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 n (1≤n≤2⋅105) — the number of problems Polycarp has prepared.

The second line of the input contains n integers a1,a2,…,an (1≤ai≤109) where ai is the topic of the i-th problem.

Output

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

Sample Input

18
2 1 2 10 2 10 10 2 2 1 10 10 10 10 1 1 10 10

Sample Output

14

Note

In the first example the optimal sequence of contests is: 2 problems of the topic 1, 4 problems of the topic 2, 8 problems of the topic 10.

解题思路

利用arr[]数组存储第i种主题的问题个数。
将其排序后,从最大的开始向前推。依次更新ans。

AC代码:

#include <iostream>
#include <algorithm>
#include <string>
#include <map>
using namespace std;
#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define endl '\n'
const int MAXN = 2e5+5;
int arr[MAXN];int main()
{SIS;int n,x,num=0,ans;map<int,int> m;cin >> n;for(int i=0;i<n;i++){cin >> x;m[x]++;}for(auto i:m) arr[num++]=i.second;sort(arr,arr+num);ans=x=arr[num-1];for(int i=num-2;i>=0;i--){x=min(x/2,arr[i]);if(!x) break;ans=max(ans,((1<<(num-i))-1)*x);}cout << ans << endl;return 0;
}

【CodeForces 1077E --- Thematic Contests】思维+贪心相关推荐

  1. CF思维联系--CodeForces -214C (拓扑排序+思维+贪心)

    ACM思维题训练集合 Furik and Rubik love playing computer games. Furik has recently found a new game that gre ...

  2. CodeForces - 1339C Powered Addition(思维+贪心)

    题目链接:点击查看 题目大意:给出一个由 n 个数组成的数列 a,选择一个最小的 k ,代表可以进行 k 次操作,对于第 t 次操作可以选择任意个位置使得 a[ i ] = a[ i ] + 2^( ...

  3. codeforces Gym 100338E Numbers (贪心,实现)

    题目:http://codeforces.com/gym/100338/attachments 贪心,每次枚举10的i次幂,除k后取余数r在用k-r补在10的幂上作为候选答案. #include< ...

  4. F 魏迟燕的自走棋(思维+贪心+并查集维护联通块/左部点配对边<=2的匈牙利)

    https://ac.nowcoder.com/acm/contest/9984/F 参考:F 魏迟燕的自走棋(贪心+并查集) 将每个人看成一个点,武器的能力值抽象成边,这样就转化成图论的模型了. 然 ...

  5. Codeforces Round #459 (Div. 2) C 思维,贪心 D 记忆化dp

    Codeforces Round #459 (Div. 2) C. The Monster 题意:定义正确的括号串,是能够全部匹配的左右括号串. 给出一个字符串,有 (.). ? 三种字符, ? 可以 ...

  6. codeforces 842 D. Vitya and Strange Lesson(01字典树+思维+贪心)

    题目链接:http://codeforces.com/contest/842/problem/D 题解:像这种求一段异或什么的都可以考虑用字典树而且mex显然可以利用贪心+01字典树,和线段树差不多就 ...

  7. CodeForces 798D 思维,贪心

    CodeForces 798D 题意:长度为 n的两个数组 a[]和 b[],要找出 k ( k<=n/2+1 )个下标,使得在两个数组中这 k个数的和乘上 2 要大于所有数的和. tags: ...

  8. Codeforces 1093C (思维+贪心)

    题面 传送门 题目大意: 有一个长n(n为偶数)的序列a 已知a满足 \(a_1≤a_2≤⋯≤a_n\) 给出一个长度为\(\frac{n}{2}\) 的序列b,定义\(b_i=a_i+a_{n-i+ ...

  9. CodeForces - 618D Hamiltonian Spanning Tree(思维+贪心)

    题目链接:点击查看 题目大意:首先给出n个点,n*(n-1)/2条边组成的无向图,边的权值为y,现在给出一棵连接n个点的树,树上的权值都是x,现在问如何在每个点只遍历一次的情况下走遍n个点,并使一路上 ...

  10. Ehab and Path-etic MEXs CodeForces - 1325C(思维+贪心)

    You are given a tree consisting of n nodes. You want to write some labels on the tree's edges such t ...

最新文章

  1. 图解在Windows下使用vim(gvim)
  2. 移动端下拉刷新原理和实例
  3. nginx编译安装与配置使用
  4. Ubuntu16.04彻底删除MySQL5.7
  5. .Net水晶报表的使用总结
  6. windows下注册和取消pg服务的命令
  7. springboot访问路径添加项目名称、tomcat端口号
  8. 力克亮相CISMA 2017,以工业4.0思维应对时尚变革
  9. mysql 导出数据 insert_mysql导出数据和导入数据
  10. (深入篇)漫游语音识别技术—带你走进语音识别技术的世界
  11. 戏子推荐伤感个性日志:其实我很脆弱
  12. 《指弹:千与千寻:Always with me》
  13. 产学交流 | 重庆师范大学计算机学院、湖北省十堰市竹溪管委会各位专家到访芝诺数据...
  14. 基于python和SQLite的NBA历年MVP变化趋势可视化分析
  15. 廖雪峰老师个人网站推荐
  16. 1. Linux命令之ps:查看进程状态
  17. javascript 实现 QQshow
  18. 数据结构课程设计报告-职工信息管理系统
  19. 关于 Token 过期问题的两种解决方案
  20. 越是没钱的时候,越要懂这10个赚钱经验

热门文章

  1. 三阶魔方层先法自动复原_Python
  2. C++之(public/protect/private)及fiend
  3. 教育知识与能力-第七章 中学德育
  4. java获取时间的年月日时分秒_Java 获取当前时间的年月日时分秒
  5. npm安装依赖包报ERR问题汇总及处理
  6. 2. Python decorate
  7. Ant Design vue v-decorate 进行数据绑定
  8. Linux Mint 19.2版安装教程
  9. 红蓝对抗--sliver 搭建
  10. a5解锁 oppo_oppoa5忘记密码了怎么强制解锁