IMohammedNasr

Untitled

May 6th, 2022
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.43 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define cin(v)        \
  4.     for (auto &i : v) \
  5.         cin >> i;
  6. #define cout(v)       \
  7.     for (auto &i : v) \
  8.         cout << i << " ";
  9. #define br cout << '\n';
  10. #define ll long long
  11. #define ull unsigned long long
  12. #define all(v) v.begin(), v.end()
  13. #define rall(v) v.rbegin(), v.rend()
  14. #define MOD 1000000007
  15. #define Time cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs" \
  16.                   << "\n";
  17.  
  18. void Warding()
  19. {
  20.     ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
  21. #ifndef ONLINE_JUDGE
  22.     freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
  23. #endif
  24. }
  25. // bool is_prime(int n)
  26. // {
  27. //     if (n <= 1)
  28. //         return false;
  29. //     for (int i = 2; i <= sqrt(n); i++)
  30. //         if (n % i == 0)
  31. //             return false;
  32. //     return true;
  33. // }
  34.  
  35. void solve()
  36. {
  37.     ll n, t, cnt = 0, flag = 0;
  38.     cin >> n >> t;
  39.     vector<ll> v(n);
  40.     unordered_map<ll, ll> m;
  41.     for (ll i = 0; i < n; i++)
  42.     {
  43.         cin >> v[i];
  44.         if (v[i] == t)
  45.             flag++;
  46.     }
  47.     if (flag == n and t == 0)
  48.     {
  49.         cout << n / 3 << " " << n % 3 << '\n';
  50.         return;
  51.     }
  52.     m[t] = flag;
  53.     for (ll i = 0; i < n; i++)
  54.     {
  55.         if (((m[t - v[i]] and v[i] != t and v[i] != 0)) and flag)
  56.         {
  57.             cnt += 3, flag--;
  58.             m[t - v[i]]--;
  59.         }
  60.         else if (v[i] != t)
  61.             m[v[i]]++;
  62.     }
  63.     if (t == 0)
  64.         cnt += flag / 3 * 3;
  65.     while ((flag >= 2 and m[0] and t != 0))
  66.             cnt += 3, flag -= 2, m[0]--;
  67.        
  68.     cout << max(cnt / 3, 0ll) << " " << n - cnt << '\n';
  69. }
  70.  
  71. // void solve()
  72. // {
  73. //     ll n, t, cnt = 0, flag = 0;
  74. //     cin >> n >> t;
  75. //     vector<ll> v(n);
  76. //     multiset<ll> mt;
  77. //     for (ll i = 0; i < n; i++)
  78. //     {
  79. //         cin >> v[i];
  80. //         if (v[i] == t)
  81. //             flag++;
  82. //     }
  83. //     for (ll i = 0; i < n; i++)
  84. //     {
  85. //         if (v[i] == t)
  86. //             continue;
  87. //         if (mt.find(t - v[i]) != mt.end() and flag)
  88. //         {
  89. //             cnt++, flag--;
  90. //             mt.erase(mt.find(t - v[i]));
  91. //         }
  92. //         else
  93. //             mt.insert(v[i]);
  94. //     }
  95. //     cout << max(cnt, 0ll) << " " << mt.size() + flag << '\n';
  96. // }
  97.  
  98. int main()
  99. {
  100.     Warding();
  101.     int t = 1;
  102.     cin >> t;
  103.     while (t--)
  104.     {
  105.         solve();
  106.     }
  107.     Time
  108. }
Advertisement
Add Comment
Please, Sign In to add comment