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> ...
随机推荐
- 使用SimpleDateFormat解析日期得到年份不正确的结果
今天写项目的时候发现日期解析结果不对,很纳闷,从控制台中看传过来的数据是对的,但解析得到数据就是错的,如下图 最终查资料发现是格式上的错误,年份的YYYY应该改成yyyy,之后就正常了. 以下是正确格 ...
- MySQL数据库初识——初窥MySQL
初步了解MySQL基本数据库语言 1.创建一个Mysql数据库 create database database_name: 2.显示所有的Mysql数据库 show databases: 3.使用 ...
- Configuration Alias
第一个里程碑 ---- 查看系统别名 [root@xilong ~]# alias alias cp='cp -i' alias egrep='egrep --color=auto' alias fg ...
- java对象中的三种状态和脏检查及刷新缓存机制
瞬时状态 瞬时状态又称临时状态.如果java对象与数据库中的数据没有任何的关联,即此java对象在数据库中没有相关联的记录,此时java对象的状态为瞬时状态,session对于 瞬时状态的ava对象是 ...
- Linux之MariaDB
MariaDB数据库的起源 MariaDB数据库管理系统是MySQL的一个分支,主要由开源社区在维护,采用GPL授权许可.开发这个分支的原因之一是:甲骨文公司收购了MySQL后,有将MySQL闭源的潜 ...
- laydate js动态添加时间
$("#test2").click(function(){ var input=$('<input/>'); $("#test1").append( ...
- thinkphp5一些文件夹用法
一.vendor通常放一些第三方的文件,如短信.支付宝等.用法: 1.在vendor中建一个文件夹: 2.在文件夹中新建一个类:主要命名空间(没有vendor ):如下面: 3.在控制器中调用,除了通 ...
- QOS-Qos标记和QOS-Policy策略
QOS-Qos标记和qos policy策略 2018年7月7日 20:29 主要标记方法 : IP ToS字段标记 IP Precedence(IP优先级) DSCP 二层 802.1p CoS ...
- Python3爬虫(一)HTTP相关基础
Infi-chu: http://www.cnblogs.com/Infi-chu/ 一.URI.URL.URN.HTTP URI:统一资源标志符 URL:是URI的一个子集 URN:是URI的另一个 ...
- python2.7练习小例子(七)
7):题目:将一个列表的数据复制到另一个列表中. 程序分析:使用列表[:]. 程序源代码: #!/usr/bin/python # -*- coding: UTF-8 -*- ...