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. kubeadm常见报错和解决方法

    k8s随着社区不断壮大国内使用率现在也是比较高的,常用的部署方式主要还是以二进制和kubeadm为主,当然1.13之前大部分人还是以二进制,但是随着版本更新kubeadm已经逐步适用于生成环境,由于k ...

  2. tomcat6添加服务

    Mysql在导入大量数据的时候就要把tomcat添加成服务 添加服务 在DOS界面下,进入Tomcat解压目录的bin目录 service.bat install

  3. php+高德地图webapi 高德jsapi 实现 当前位置与目标位置距离 并按照距离排序(坐标逆转换)

    <script type="text/javascript" src="https://api.map.baidu.com/api?v=2.0&ak='自己 ...

  4. Laravel POST请求API接口 使用validate表单验证返回欢迎页

    突然遇到的问题  就是使用Laravel进行开发API接口的时候  发现在表单验证不通过的时候返回了登录页 猜测问题应该是因为表单验证失败后进行了重定向导致的 因为返回状态码200 网上找了好久没找到 ...

  5. java服务端项目开发规范

    更新内容 2015-03-13 (请先更新svn的mybatis.xml.BaseMapper.java.Pager.java文件) 加入测试类规范 加入事物控制规范 加入mapper接口规则 ...

  6. PHP代码统计文件大小(自动确定单位)

    php中有一个系统自带的计算文件大小的函数,就是filesize(),但是这个函数是以字节为单位的,但是在一些情况下,我们需要很直观的了解一个文件大小,就不仅仅需要字节B这个单位了,还需要KB,MB, ...

  7. ts packet解析

    (1)TS流是基于Packet的位流格式,每个包是188字节或者204字节(一般是188字节,204字节的格式仅仅是在188字节的Packet后部加上16字节的CRC数据,其他格式是一样的),整个TS ...

  8. R语言学习笔记(十六):构建分割点函数

    选取预测概率的分割点 cutoff<- function(n,p){ pp<-1 i<-0 while (pp>=0.02) { model.predfu<-rep(&q ...

  9. FPGA算法学习(1) -- Cordic(圆周系统之旋转模式)

    三角函数的计算是个复杂的主题,有计算机之前,人们通常通过查找三角函数表来计算任意角度的三角函数的值.这种表格在人们刚刚产生三角函数的概念的时候就已经有了,它们通常是通过从已知值(比如sin(π/2)= ...

  10. 20145202马超 实验二《Java面向对象程序设计》实验报告

    实验二 Java面向对象程序设计 实验内容 1.初步掌握单元测试和TDD 2.理解并掌握面向对象三要素:封装.继承.多态 3.初步掌握UML建模 4.熟悉S.O.L.I.D原则 5.了解设计模式 实验 ...