Advertisement
Junaid_Hossain

Two Sets

Dec 23rd, 2023
733
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.58 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. long long sumOf(vector<int> one, vector<int> two, int n)
  5. {
  6.     long long sumOne = 0, sumTwo = 0;
  7.     for (int i = 0; i < one.size(); i++)
  8.         sumOne += one[i];
  9.     for (int i = 0; i < two.size(); i++)
  10.         sumTwo += two[i];
  11.     // cout << sumOne << sumTwo << endl;
  12.  
  13.     if (sumOne == sumTwo)
  14.         return 1;
  15.     else
  16.         return 0;
  17. }
  18.  
  19. int main()
  20. {
  21.     int n;
  22.     cin >> n;
  23.     int arr[n];
  24.     int temp = n;
  25.     vector<int> listOne;
  26.     vector<int> listTwo;
  27.  
  28.     if (n % 2 == 0)
  29.     {
  30.         int i = 1;
  31.         int j = n;
  32.         while (i <= n / 2)
  33.         {
  34.  
  35.             if (i % 2 != 0)
  36.             {
  37.                 listOne.push_back(i);
  38.                 listOne.push_back(j);
  39.             }
  40.             else
  41.             {
  42.  
  43.                 listTwo.push_back(i);
  44.                 listTwo.push_back(j);
  45.             }
  46.  
  47.             i++;
  48.             j--;
  49.         }
  50.  
  51.         if (listOne.size() != listTwo.size())
  52.         {
  53.             cout << "NO" << endl;
  54.         }
  55.         else
  56.         {
  57.             cout << "YES" << endl;
  58.             cout << listOne.size() << endl;
  59.             for (int k = 0; k < listOne.size(); k++)
  60.             {
  61.                 cout << listOne[k] << " ";
  62.             }
  63.  
  64.             cout << listTwo.size() << endl;
  65.             cout << listTwo.size() << endl;
  66.             for (int k = 0; k < listTwo.size(); k++)
  67.             {
  68.                 cout << listTwo[k] << " ";
  69.             }
  70.         }
  71.     }
  72.     else
  73.     {
  74.         int i = 1;
  75.         int j = n - 1;
  76.         while (i <= n / 2)
  77.         {
  78.             if (i == n / 2)
  79.             {
  80.                 listTwo.push_back(n);
  81.                 break;
  82.             }
  83.  
  84.             if (i % 2 != 0)
  85.             {
  86.                 listOne.push_back(i);
  87.                 listOne.push_back(j);
  88.             }
  89.             else
  90.             {
  91.  
  92.                 listTwo.push_back(i);
  93.                 listTwo.push_back(j);
  94.             }
  95.  
  96.             i++;
  97.             j--;
  98.         }
  99.  
  100.         if (sumOf(listOne, listTwo, n) == 0)
  101.         {
  102.             cout << "NO" << endl;
  103.         }
  104.         else
  105.         {
  106.             cout << "YES" << endl;
  107.             cout << listOne.size() << endl;
  108.             for (int k = 0; k < listOne.size(); k++)
  109.             {
  110.                 cout << listOne[k] << " ";
  111.             }
  112.  
  113.             cout << endl;
  114.             cout << listTwo.size() << endl;
  115.             for (int k = 0; k < listTwo.size(); k++)
  116.             {
  117.                 cout << listTwo[k] << " ";
  118.             }
  119.         }
  120.     }
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement