fork download
  1. #include <iostream>
  2. #include <algorithm>
  3. using namespace std;
  4.  
  5. int compare (int a, int b)
  6. {
  7. return a < b;
  8. }
  9.  
  10.  
  11. int main()
  12. {
  13. int l, k, p = 1;
  14. cin >> l >> k;
  15. int *tab = new int[l];
  16. for (int i = 0; i < l; i++)
  17. cin >> tab[i];
  18. sort(tab, tab+l, compare);
  19. if (k == 1)
  20. cout << tab[l - 1] << endl;
  21. else
  22. {
  23. while (p <= k)
  24. {
  25. cout << tab[l - 1] << endl;
  26. l--;
  27. p++;
  28. }
  29. }
  30. return 0;
  31. }
Success #stdin #stdout 0s 3480KB
stdin
5 3
5 2 1 5 2
stdout
5
5
2