Advertisement
yoyoboyss

Untitled

May 23rd, 2019
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.12 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. const int NMAX = 100000;
  5.  
  6. int p, N;
  7. int v[NMAX];
  8.  
  9. long long produs(int v[NMAX]){
  10. long long prod = 0;
  11. prod = v[N] * v[1];
  12. for(int i = 1; i <= N - 1; i++)
  13. prod = prod + v[i] * v[i+1];
  14.  
  15. return prod;
  16. }
  17.  
  18. int main(){
  19.  
  20. freopen("roboti3.in", "r", stdin);
  21. freopen("roboti3.out", "w", stdout);
  22.  
  23. scanf("%d%d", &p, &N);
  24. for(int i = 1; i <= N; i++)
  25. scanf("%d", &v[i]);
  26.  
  27. if(p == 1){
  28. int scmax = 0, val = 1;
  29. int cresc[NMAX];
  30. cresc[1] = 1;
  31. for(int i = 2; i <= N; i++){
  32. if(v[i] > v[i-1])
  33. cresc[i] = cresc[i-1] + 1;
  34. else{
  35. val++;
  36. cresc[i] = 1;
  37. }
  38. if(cresc[i] > scmax)
  39. scmax = cresc[i];
  40. }
  41. if(v[N] < v[1]){
  42. cresc[1] = cresc[N] + 1;
  43. int i = 2;
  44. while(v[i] > v[i-1]){
  45. cresc[i] = cresc[i-1] + 1;
  46. i++;
  47. }
  48. if(cresc[i-1] > scmax)
  49. scmax = cresc[i-1];
  50. }
  51. printf("%d", scmax);
  52. } else {
  53. int pmax[NMAX], cnt[NMAX/100], af[NMAX/100];
  54. int i, mns = 0;
  55. sort(v+1, v+N+1);
  56. /*for(i = 1; i <= N; i++)
  57. printf("%d ", v[i]);
  58. printf("\n\n");*/
  59.  
  60. for(i = 1; i <= N / 2; i++)
  61. pmax[i] = v[2*i];
  62. for(int j = N % 2; j <= N - N / 2; j++, i++)
  63. pmax[i] = v[N - 2 * j - 1 + N % 2];
  64.  
  65. for(i = 1; i <= N; i++)
  66. printf("%d ", pmax[i]);
  67. for(i = N / 2 + 1 - N % 2; i <= N; i++){
  68. cnt[pmax[i]]++;
  69. if(cnt[pmax[i]] > 1)
  70. af[i] = 1;
  71. }
  72.  
  73. if(pmax[N] == pmax[1]){
  74. printf("%d ", pmax[1]);
  75. mns = 1;
  76. }
  77. for(int i = 1; i <= N - mns; i++){
  78. if(!af[i])
  79. printf("%d ", pmax[i]);
  80. while(cnt[pmax[i]] > 1){
  81. printf("%d ", pmax[i]);
  82. cnt[pmax[i]]--;
  83. }
  84. }
  85.  
  86. }
  87.  
  88. return 0;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement