IMohammedNasr

Untitled

May 6th, 2022
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.99 KB | None | 0 0
  1. void solve()
  2. {
  3.     ll n, t, cnt = 0, flag = 0;
  4.     cin >> n >> t;
  5.     vector<ll> v(n);
  6.     unordered_map<ll, ll> m;
  7.     for (ll i = 0; i < n; i++)
  8.     {
  9.         cin >> v[i];
  10.         if (v[i] == t)
  11.             flag++;
  12.     }
  13.     if (flag == n and t == 0)
  14.     {
  15.         cout << n / 3 << " " << n % 3 << '\n';
  16.         return;
  17.     }
  18.     m[t] = flag;
  19.     for (ll i = 0; i < n; i++)
  20.     {
  21.         if (((m[t - v[i]] and v[i] != t)) and flag)
  22.         {
  23.             if (t - v[i] == t)
  24.             {
  25.                 if (flag >= 2)
  26.                 {
  27.                     flag -= 2;
  28.                     cnt += 3;
  29.                     m[t] -= 2;
  30.                     continue;
  31.                 }
  32.                 else
  33.                     continue;
  34.             }
  35.             cnt += 3, flag--;
  36.             m[t - v[i]]--;
  37.         }
  38.         else if (v[i] != t)
  39.             m[v[i]]++;
  40.     }
  41.     if (t + t == t)
  42.         cnt += flag / 3 * 3;
  43.     cout << max(cnt / 3, 0ll) << " " << n - cnt << '\n';
  44. }
Advertisement
Add Comment
Please, Sign In to add comment