博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Ehab and subtraction(思维题)
阅读量:4701 次
发布时间:2019-06-09

本文共 1666 字,大约阅读时间需要 5 分钟。

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

You're given an array aa. You should repeat the following operation kk times: find the minimum non-zero element in the array, print it, and then subtract it from all the non-zero elements of the array. If all the elements are 0s, just print 0.

Input

The first line contains integers nn and kk (1≤n,k≤105)(1≤n,k≤105), the length of the array and the number of operations you should perform.

The second line contains nn space-separated integers a1,a2,…,ana1,a2,…,an (1≤ai≤109)(1≤ai≤109), the elements of the array.

Output

Print the minimum non-zero element before each operation in a new line.

Examples

input

Copy

3 51 2 3

output

Copy

11100

input

Copy

4 210 3 5 3

output

Copy

32

Note

In the first sample:

In the first step: the array is [1,2,3][1,2,3], so the minimum non-zero element is 1.

In the second step: the array is [0,1,2][0,1,2], so the minimum non-zero element is 1.

In the third step: the array is [0,0,1][0,0,1], so the minimum non-zero element is 1.

In the fourth and fifth step: the array is [0,0,0][0,0,0], so we printed 0.

In the second sample:

In the first step: the array is [10,3,5,3][10,3,5,3], so the minimum non-zero element is 3.

In the second step: the array is [7,0,2,0][7,0,2,0], so the minimum non-zero element is 2.

题解:如果直接暴力去找的话必然是会超时的,我们可以利用c++排序的功能排序好,然后进行比较每次输出最小的就大大提高了效率,从而不会是超时

代码:

#include
#include
#include
#include
using namespace std;int main(){ int n,m; cin>>n>>m; int a[100005]; for(int t=0;t

 

转载于:https://www.cnblogs.com/Staceyacm/p/10781952.html

你可能感兴趣的文章
Rpgmakermv(38)MOG_Theatrhythm
查看>>
karma与webpack结合
查看>>
poj 1273 Drainage Ditches 的测试数据
查看>>
【转】独立游戏设计宣言
查看>>
adb命令
查看>>
QtCreator异常
查看>>
PowerDesigner导出表到word
查看>>
使用 string 的一些规则
查看>>
gnome-terminal的一些调整
查看>>
POJ 1273 Drainage Ditches
查看>>
POJ 1733 Parity game
查看>>
js晋级篇——前端内存泄漏探讨
查看>>
Drupal 出错的解决办法
查看>>
js正则
查看>>
thrift源码阅读笔记
查看>>
iOS UI基础-4.0应用程序管理
查看>>
在CentOS 6.4 x86_32中使用Rhythmbox听MP3
查看>>
sys模块
查看>>
BZOJ3073 : [Pa2011]Journeys
查看>>
BZOJ2213 : [Poi2011]Difference
查看>>