Advertisement
a53

Cioc_of

a53
Feb 1st, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.62 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. long long v[200050], w[200050], x;
  6.  
  7. int main()
  8. {
  9. ifstream fin("cioc.in");
  10. ofstream fout("cioc.out");
  11.  
  12. int c, n, k, i;
  13.  
  14. fin >> c >> n >> k;
  15. for(i = 0; i < n; ++i)
  16. {
  17. fin >> v[i];
  18. w[i] = v[i];
  19. }
  20.  
  21. nth_element(w, w+k-1, w+n);
  22. x = w[k-1];
  23.  
  24. cout << x;
  25.  
  26. k = count_if(v, v+n, [&](long long i){ return (i <= x); });
  27. if(c == 1)
  28. fout << k;
  29. else
  30. {
  31. c = k;
  32. for(i = n-1; i >= 0; --i)
  33. {
  34. if(v[i] <= x)
  35. {
  36. v[i+c] = 2 * v[i];
  37. --c;
  38. }
  39. v[i+c] = v[i];
  40. }
  41.  
  42. for(i = 0; i < n + k; ++i)
  43. (fout << v[i]).put(' ');
  44. }
  45. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement