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

You are given an array ss consisting of nn integers.

You have to find any array tt of length kk such that you can cut out maximum number of copies of array tt from array ss.

Cutting out the copy of tt means that for each element titi of array tt you have to find titi in ss and remove it from ss. If for some titi you cannot find such element in ss, then you cannot cut out one more copy of tt. The both arrays can contain duplicate elements.

For example, if s=[1,2,3,2,4,3,1]s=[1,2,3,2,4,3,1] and k=3k=3 then one of the possible answers is t=[1,2,3]t=[1,2,3]. This array tt can be cut out 22 times.

  • To cut out the first copy of tt you can use the elements [1,2––,3,2,4,3––,1––][1,2_,3,2,4,3_,1_] (use the highlighted elements). After cutting out the first copy of tt the array ss can look like [1,3,2,4][1,3,2,4].
  • To cut out the second copy of tt you can use the elements [1––,3––,2––,4][1_,3_,2_,4]. After cutting out the second copy of tt the array ss will be [4][4].

Your task is to find such array tt that you can cut out the copy of tt from ss maximum number of times. If there are multiple answers, you may choose any of them.

Input

The first line of the input contains two integers nn and kk (1≤k≤n≤2⋅1051≤k≤n≤2⋅105) — the number of elements in ss and the desired number of elements in tt, respectively.

The second line of the input contains exactly nn integers s1,s2,…,sns1,s2,…,sn (1≤si≤2⋅1051≤si≤2⋅105).

Output

Print kk integers — the elements of array tt such that you can cut out maximum possible number of copies of this array from ss. If there are multiple answers, print any of them. The required array tt can contain duplicate elements. All the elements of tt (t1,t2,…,tkt1,t2,…,tk) should satisfy the following condition: 1≤ti≤2⋅1051≤ti≤2⋅105.

Examples
input

Copy
7 3
1 2 3 2 4 3 1
output

Copy
1 2 3
input

Copy
10 4
1 3 1 3 10 3 7 7 12 3
output

Copy
7 3 1 3
input

Copy
15 2
1 2 1 1 1 2 1 1 2 1 2 1 1 1 1
output

Copy
1 1
Note

The first example is described in the problem statement.

In the second example the only answer is [7,3,1,3][7,3,1,3] and any its permutations. It can be shown that you cannot choose any other array such that the maximum number of copies you can cut out would be equal to 22.

In the third example the array tt can be cut out 55 times.

代码:

#include <bits/stdc++.h>
using namespace std; const int maxn = 2e5 + 10;
int n, k;
int a[maxn];
int times[maxn]; bool can(int x) {
int cnt = 0;
for(int i = 1; i < maxn; i ++)
cnt += times[i] / x;
if(cnt >= k) return true;
return false;
} int main() {
memset(times, 0, sizeof(times));
scanf("%d%d", &n, &k);
for(int i = 1; i <= n; i ++) {
scanf("%d", &a[i]);
times[a[i]] ++;
} int l = 1, r = n, mid, maxx = 1;
while(l <= r) {
mid = (r - l) / 2 + l;
if(can(mid)) maxx = mid, l = mid + 1;
else r = mid - 1;
} int ans[maxn];
int rec = 0;
for(int i = 1; i < maxn; i ++) {
if(times[i] >= maxx)
for(int j = 1; j <= times[i] / maxx; j ++) {
ans[rec ++] = i;
if(rec == k) break;
}
} for(int i = 0; i < k; i ++) {
printf("%d", ans[i]);
printf("%s", i != k - 1 ? " " : "\n");
}
return 0;
}

  今天是丧气的一天

CodeForces Round #521 (Div.3) D. Cutting Out的更多相关文章

  1. 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 ...

  2. Codeforces Round #521 (Div. 3) E. Thematic Contests(思维)

    Codeforces Round #521 (Div. 3)  E. Thematic Contests 题目传送门 题意: 现在有n个题目,每种题目有自己的类型要举办一次考试,考试的原则是每天只有一 ...

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

    http://codeforces.com/contest/1077/problem/E output standard output Polycarp has prepared nn competi ...

  4. 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 ...

  5. 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 ...

  6. 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 ...

  7. Codeforces Round #521 (Div.3)题解

    A过水,不讲 题解 CF1077B [Disturbed People] 这题就是个显而易见的贪心可是我考场上差点没想出来 显然把一户被打扰的人家的右边人家的灯关掉肯定比把左边的灯关掉 从左到右扫一遍 ...

  8. Codeforces Round #521 (Div. 3)

    B 题过的有些牵强,浪费了很多时间,这种题一定想好思路和边界条件再打,争取一发过.  D 题最开始读错题,后面最后发现可以重复感觉就没法做了,现在想来,数据量大,但是数据范围小枚举不行,二分还是可以的 ...

  9. Codeforces Round #521 Div. 3 玩耍记

    A:签到. #include<iostream> #include<cstdio> #include<cmath> #include<cstdlib> ...

随机推荐

  1. redis 高性能应用

    redis可达到512M/per key 512M=512*1024KB=512*1024*1000B=512*1024*1000*8bit=40亿+ 化整为零40亿,也就是说一位代表一个用户,40亿 ...

  2. 构建高可靠hadoop集群之5-服务级别授权

    本人翻译自: http://hadoop.apache.org/docs/r2.8.0/hadoop-project-dist/hadoop-common/ServiceLevelAuth.html ...

  3. 关于Linux环境变量DISPLAY的设置

    问题描述:在个人PC(windows系统)安装了虚拟机,虚拟机中安装了Linux系统,Linux系统中安装了wireshark和firefox这两个程序,网上查阅可以通过设置DISPLAY环境变量指向 ...

  4. DevOps - 项目私库 - Nexus Repository

    相关链接 Sonatype官网:https://www.sonatype.com Products: Nexus Repository OSS2.x & 3.x Documentation:  ...

  5. CentOS7下PHP7.2安装redis扩展

    1.安装phpize(存在忽略) yum install php-devel 2.下载扩展源码包,直接用wget,一般放在 /usr/local/src wget https://github.com ...

  6. JS高级. 04 增删改查面向对象版歌曲管理、递归、

    增 数组.push() 删 数组.splice(开始删除索引,删除几个) 在当前对象中调用当前对象的方法中和属性,必须用this调用 nodeType判断节点类型 节点.nodeType ==  1: ...

  7. sklearn fit transform fit_transform

    scikit-learn提供了一系列转换库,他们可以清洗,降维,提取特征等. 在数据转换中有三个很重要的方法,fit,fit_transform,transform ss=StandardScaler ...

  8. php+sqlserver处理读取decimal 类型数据,不满1的数字会去掉0的问题

    php+sqlserver处理读取decimal 类型数据,如果数据不满1,会去掉0的问题.比如读取的数据是 0.05,会显示 .05 function convert_number($number) ...

  9. tomcat+nginx+keepalived的配置

    tomcat+nginx+keepalived的配置 1.在官网上下载Tomcat 2.将压缩包解压,并且移动到/opt/data/的目录下. .tar.gz /opt/data/ 3.进入到Tomc ...

  10. 3. 进程间通信IPC

    一.概念 IPC: 1)在linux环境中的每个进程各自有不同的用户地址空间.任何一个进程的全局变量在另一个进程中都看不到,所以进程和进程之间是不能相互访问. 2)如果进程间要交换数据必须通过内核,在 ...