jakaria_hossain

codeforce - Two Shuffled Frequnces

Mar 31st, 2019
70
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. int main()
  4. {
  5. int n;
  6. cin>>n;
  7. int ara[n+1],inc[n+1],dec[n+1],in=0,de=0;
  8. map<int,int>mp;
  9. bool ok=false;
  10. for(int i=0;i<n;i++)
  11. {
  12. cin>>ara[i];
  13. mp[ara[i]]++;
  14. }
  15. sort(ara,ara+n);
  16. for(int i=0;i<n;i++)
  17. {
  18. if(mp[ara[i]]==1)dec[de++]=ara[i];
  19. else if(mp[ara[i]]==2)
  20. {
  21. dec[de++]=ara[i];
  22. inc[in++]=ara[i];
  23. i++;
  24. }
  25. else
  26. {
  27. ok=true;
  28. break;
  29. }
  30. }
  31. if(ok)
  32. {
  33. printf("NO\n");
  34. }
  35. else
  36. {
  37. printf("YES\n");
  38. if(in==0)
  39. {
  40. printf("0\n");
  41. }
  42. else
  43. {
  44. sort(inc,inc+in);
  45. printf("%d\n",in);
  46. for(int i=0;i<in;i++)
  47. printf("%d ",inc[i]);
  48. printf("\n");
  49. }
  50. sort(dec,dec+de);
  51. printf("%d\n",de);
  52. for(int i=de-1;i>=0;i--)
  53. {
  54. printf("%d ",dec[i]);
  55. }
  56. printf("\n");
  57. }
  58. return 0;
  59. }
RAW Paste Data