fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main() {
  6.  
  7. long long n;
  8. cin>>n;
  9.  
  10. long long sum = (n*(n+1))/2;
  11.  
  12. vector<long long> set1;
  13. vector<long long> set2;
  14. vector<long long> vis(n+1,0);
  15. long long maxElement=n;
  16.  
  17. if(sum%2 == 1)
  18. {
  19. cout<<"NO"<<endl;
  20. }
  21. else
  22. {
  23. cout<<"YES"<<endl;
  24. long long set1Sum=0;
  25.  
  26. //cout<<set1Sum<<" "<<sum/2<<endl;
  27.  
  28. while(set1Sum < (sum/2))
  29. {
  30.  
  31. if((sum/2-set1Sum) > maxElement)
  32. {
  33. set1.push_back(maxElement);
  34. vis[maxElement]=1;
  35. set1Sum+=maxElement;
  36. maxElement--;
  37. }
  38. else
  39. {
  40. set1.push_back(sum/2-set1Sum);
  41. vis[sum/2-set1Sum]=1;
  42. set1Sum+=sum/2-set1Sum;
  43. }
  44. //cout<<set1Sum<<endl;
  45. }
  46.  
  47. for(int i=1;i<=n;i++)
  48. {
  49. if(vis[i] == 0)
  50. {
  51. set2.push_back(i);
  52. }
  53. }
  54.  
  55. cout<<set1.size()<<endl;
  56. for(int i=0;i<set1.size();i++)
  57. {
  58. if(i == set1.size()-1)
  59. {
  60. cout<<set1[i]<<endl;
  61. }
  62. else
  63. {
  64. cout<<set1[i]<<" ";
  65. }
  66. }
  67.  
  68. cout<<set2.size()<<endl;
  69. for(int i=0;i<set2.size();i++)
  70. {
  71. if(i == set2.size()-1)
  72. {
  73. cout<<set2[i]<<endl;
  74. }
  75. else
  76. {
  77. cout<<set2[i]<<" ";
  78. }
  79. }
  80.  
  81. }
  82.  
  83. return 0;
  84. }
Success #stdin #stdout 0.01s 5280KB
stdin
7
stdout
YES
3
7 6 1
4
2 3 4 5