Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.46 KB | None | 0 0
  1. /******************************************************************************
  2.  
  3. Online C++ Compiler.
  4. Code, Compile, Run and Debug C++ program online.
  5. Write your code in this editor and press "Run" button to compile and execute it.
  6.  
  7. *******************************************************************************/
  8.  
  9. #include <iostream>
  10.  
  11. using namespace std;
  12.  
  13. int main()
  14. {
  15. int n, k, m, x = 1000, w = 1, t = 0, max = 0 , l;
  16. cin>>n;
  17. cin>>k;
  18. int a[1000];
  19. int b[1000];
  20. int c[1000];
  21. for(int i = 0; i < n; i++)
  22. {
  23. a[i] = 0;
  24. b[i] = 0;
  25. }
  26. for(int i = 0;i < n; i++)
  27. {
  28. cin>>m;
  29. if(a[m-1] == 0)
  30. {
  31. c[t] = m-1;
  32. t++;
  33. }
  34. a[m-1]++;
  35.  
  36. }
  37. for(int i = 0; i < t; i++)
  38. {
  39. if(max < a[с[i]]
  40. {
  41. max = a[c[i]];
  42. }
  43. }
  44. for(int i = 0; i < t; i++)
  45. {
  46. if(a[c[i]] == max)
  47. {
  48. l++;
  49. }
  50. }
  51. if( (max > (n/k) + 1) or ( (max == (n/k) + 1) and (l > n%k) ) )
  52. {
  53. cout<<-1;
  54. }
  55. else
  56. {
  57. for(int i = 0; i < t; i++)
  58. {
  59. if(max == (n/k) + 1 and a[c[i]] == max)
  60. {
  61. for(int j = 0; j < a[c[i]]; j++)
  62. {
  63. b[w] = c[i];
  64. w += k
  65. }
  66. }
  67.  
  68. }
  69. }
  70.  
  71. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement