CodeForces Round #521 (Div.3) E. Thematic Contests
http://codeforces.com/contest/1077/problem/E
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.
The first line of the input contains one integer nn (1≤n≤2⋅1051≤n≤2⋅105) — the number of problems Polycarp has prepared.
The second line of the input contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1091≤ai≤109) where aiai is the topic of the ii-th problem.
Print one integer — the maximum number of problems in the set of thematic contests.
18
2 1 2 10 2 10 10 2 2 1 10 10 10 10 1 1 10 10
14
10
6 6 6 3 6 1000000000 3 3 6 6
9
3
1337 1337 1337
3
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\n", ans);
return 0;
}
CodeForces Round #521 (Div.3) E. Thematic Contests的更多相关文章
- Codeforces Round #521 (Div. 3) E. Thematic Contests(思维)
Codeforces Round #521 (Div. 3) E. Thematic Contests 题目传送门 题意: 现在有n个题目,每种题目有自己的类型要举办一次考试,考试的原则是每天只有一 ...
- Codeforces Round #521 (Div. 3) E. Thematic Contests (离散化,二分)
题意:有\(n\)个话题,每次都必须选取不同的话题,且话题数必须是上次的两倍,第一次的话题数可以任意,问最多能选取多少话题数. 题解:我们首先用桶来记录不同话题的数量,因为只要求话题的数量,与话题是多 ...
- Codeforces Round #521 (Div. 3) D. Cutting Out 【二分+排序】
任意门:http://codeforces.com/contest/1077/problem/D D. Cutting Out time limit per test 3 seconds memory ...
- CodeForces Round #521 (Div.3) D. Cutting Out
http://codeforces.com/contest/1077/problem/D You are given an array ss consisting of nn integers. Yo ...
- Codeforces Round #521 (Div. 3) F1. Pictures with Kittens (easy version)
F1. Pictures with Kittens (easy version) 题目链接:https://codeforces.com/contest/1077/problem/F1 题意: 给出n ...
- CodeForces Round #521 (Div.3) B. Disturbed People
http://codeforces.com/contest/1077/problem/B There is a house with nn flats situated on the main str ...
- CodeForces Round #521 (Div.3) A. Frog Jumping
http://codeforces.com/contest/1077/problem/A A frog is currently at the point 00 on a coordinate axi ...
- Codeforces Round #521 (Div. 3)
B 题过的有些牵强,浪费了很多时间,这种题一定想好思路和边界条件再打,争取一发过. D 题最开始读错题,后面最后发现可以重复感觉就没法做了,现在想来,数据量大,但是数据范围小枚举不行,二分还是可以的 ...
- Codeforces Round #521 Div. 3 玩耍记
A:签到. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> ...
随机推荐
- 极光推送小结 - iOS
此次即友盟分享小结(友盟分享小结 - iOS)之后对推送也进行了一版优化.此次分享内容依然基于已经成功集成 SDK 后 code 层级部分. 注:此次分享基于 SDK 3.1.0,若版本相差较大,仅供 ...
- 数据库查询服务DBCacheServer
各个业务系统,都需要查询各类数据库; 一般查询数据库都是客户端自己连接,根据现在的情况,存在以下几点问题 1.客户端连接很多,连接大小,峰值不可控 2.客户端SQL程序员自己写,参差不齐 3.SQL书 ...
- 关于Ext.js和Ext.Net的杂谈
最近几年比较火的前端js框架extjs 算是其中的佼佼者.统一的UI设计,强悍的组件及丰富的插件,对浏览器良好的兼容性等优点使得许多公司使用Extjs,同时也使得无数程序猿开始研究这个玩意也包括我在内 ...
- elasticsearch 5.x 系列之六 文档索引,更新,查询,删除流程
一.elasticsearch index 索引流程 步骤: 客户端向Node1 发送索引文档请求 Node1 根据文档ID(_id字段)计算出该文档应该属于shard0,然后请求路由到Node3的P ...
- springboot学习(2)
WebMvcConfigurerAdapter 在springboot2.0及以上版本过时问题 WebMvcConfigurerAdapter已经过时,替代方案: 1 实现 WebMvcConfigu ...
- CRC校验8
什么是CRC校验? CRC即循环冗余校验码:是数据通信领域中最常用的一种查错校验码,其特征是信息字段和校验字段的长度可以任意选定.循环冗余检查(CRC)是一种数据传输检错功能,对数据进行多项式计算,并 ...
- PAT-B java实现
注意:java提交PAT时,不需要加package : 类名必须是Main. 1001 害死人不偿命的(3n+1)猜想 (15) 输入格式:每个测试输入包含1个测试用例,即给出自然数n的值. 输出格式 ...
- mac制作U盘启动器
Infi-chu: http://www.cnblogs.com/Infi-chu/ 一.所需工具及必要条件: 1. 首先需要一个大于16GB U盘. 2.电脑系统版本应该大于10.11.X(因为之前 ...
- JSON初体验(二):Gson解析
今天,我们来介绍一下Gson的jar包的用法. JSON解析之Gson 特点:编码简介,谷歌官方推荐 数据之间的转换: 1.将json格式的字符串{}转换成为java对象 API: <T> ...
- 微信H5支付 在其他浏览器调用微信支付
微信H5支付的相关资料不是很多.不过步骤上来说不是很复杂 比公众号支付简单很多. 先上官方文档吧 https://pay.weixin.qq.com/wiki/doc/api/H5.php?chapt ...