Advertisement
Valkyrie006

Untitled

Oct 13th, 2021
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.25 KB | None | 0 0
  1. void solve()
  2. {
  3.     ll n;
  4.     cin >> n;
  5.     vector<ll> A(n);
  6.     for (ll i = 0; i < n; i++)
  7.         cin >> A[i];
  8.     ll mx = accumulate(A.begin(), A.end(), 0LL) / 2;
  9.     vector<vector<ll>> ans(3);
  10.     ll i = 0, sum = 0;
  11.     for (i; i < n - 2; i++)
  12.     {
  13.         if (mx >= sum + A[i] || ans[0].size() == 0)
  14.         {
  15.             sum += A[i];
  16.             ans[0].push_back(A[i]);
  17.         }
  18.         else
  19.         {
  20.             break;
  21.         }
  22.     }
  23.     sum = 0;
  24.     for (i; i < n - 1; i++)
  25.     {
  26.         if (mx >= sum + A[i] || ans[1].size() == 0)
  27.         {
  28.             sum += A[i];
  29.             ans[1].push_back(A[i]);
  30.         }
  31.         else
  32.         {
  33.             break;
  34.         }
  35.     }
  36.     sum = 0;
  37.     for (i; i < n; i++)
  38.     {
  39.         if (mx >= sum + A[i] || ans[2].size() == 0)
  40.         {
  41.             sum += A[i];
  42.             ans[2].push_back(A[i]);
  43.         }
  44.         else
  45.         {
  46.             break;
  47.         }
  48.     }
  49.     if (i != n)
  50.     {
  51.         cout << "NO" << endl;
  52.     }
  53.     else
  54.     {
  55.         cout << "YES" << endl;
  56.         for (ll i = 0; i < 3; i++)
  57.         {
  58.             for (auto a : ans[i])
  59.             {
  60.                 cout << a << " ";
  61.             }
  62.             cout << endl;
  63.         }
  64.     }
  65.     return;
  66. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement