Advertisement
Guest User

Untitled

a guest
Dec 16th, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int block[10005],L,K,a[10005],b,c,Z[10005];
  6.  
  7. int main()
  8. {
  9. cin >> L >> K;
  10.  
  11. for ( int i = 0; i < K; i++ )
  12. {
  13. cin >> block[i];
  14. Z[block[i]] = block[i];
  15. }
  16.  
  17. for ( int i = 0; i < L; i++ )
  18. {
  19. a[block[i]] = 1;
  20. }
  21.  
  22. if ( L%2 == 1 && a[L/2] == 1 )
  23. {
  24. cout << block[a[block[L/2]]];
  25. return 0;
  26. }
  27. else
  28. {
  29. for ( int i = 0; i < L/2; i++ )
  30. {
  31. if ( a[i] == 1 ) b++;
  32. }
  33. for ( int i = L/2+1; i <= L; i++ )
  34. {
  35. if ( a[i] == 1 ) c++;
  36. }
  37. }
  38.  
  39. int j = 0;
  40. if ( b != 1 || c != 1 )
  41. {
  42. while ( b != 1 )
  43. {
  44. if ( a[j] == 1 )
  45. {
  46. a[j] = 0;
  47. b--;
  48. }
  49. j++;
  50. }
  51.  
  52. j = L;
  53.  
  54. while ( c != 1 )
  55. {
  56. if ( a[j] == 1 )
  57. {
  58. a[j] = 0;
  59. c--;
  60. }
  61. j--;
  62. }
  63. }
  64.  
  65.  
  66. for ( int i = 0; i < L; i++ )
  67. {
  68. if ( a[i] == 1 )
  69. {
  70. cout << Z[i] << " ";
  71. }
  72. }
  73.  
  74.  
  75.  
  76. //for ( int i = 0; i < L; i++ )
  77. {
  78. //cout << a[i] << " ";
  79. }
  80.  
  81. return 0;
  82. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement