Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <bits/stdc++.h>
- using namespace std;
- #define cin(v) \
- for (auto &i : v) \
- cin >> i;
- #define cout(v) \
- for (auto &i : v) \
- cout << i << " ";
- #define br cout << '\n';
- #define ll long long
- #define ull unsigned long long
- #define all(v) v.begin(), v.end()
- #define rall(v) v.rbegin(), v.rend()
- #define MOD 1000000007
- #define Time cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " Secs" \
- << "\n";
- void Warding()
- {
- ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
- #ifndef ONLINE_JUDGE
- freopen("input.txt", "r", stdin), freopen("output.txt", "w", stdout);
- #endif
- }
- // bool is_prime(int n)
- // {
- // if (n <= 1)
- // return false;
- // for (int i = 2; i <= sqrt(n); i++)
- // if (n % i == 0)
- // return false;
- // return true;
- // }
- void solve()
- {
- ll n, t, cnt = 0, flag = 0;
- cin >> n >> t;
- vector<ll> v(n);
- unordered_map<ll, ll> m;
- for (ll i = 0; i < n; i++)
- {
- cin >> v[i];
- if (v[i] == t)
- flag++;
- }
- if (flag == n and t == 0)
- {
- cout << n / 3 << " " << n % 3 << '\n';
- return;
- }
- m[t] = flag;
- for (ll i = 0; i < n; i++)
- {
- if (((m[t - v[i]] and v[i] != t and v[i] != 0)) and flag)
- {
- cnt += 3, flag--;
- m[t - v[i]]--;
- }
- else if (v[i] != t)
- m[v[i]]++;
- }
- if (t == 0)
- cnt += flag / 3 * 3;
- while ((flag >= 2 and m[0] and t != 0))
- cnt += 3, flag -= 2, m[0]--;
- cout << max(cnt / 3, 0ll) << " " << n - cnt << '\n';
- }
- // void solve()
- // {
- // ll n, t, cnt = 0, flag = 0;
- // cin >> n >> t;
- // vector<ll> v(n);
- // multiset<ll> mt;
- // for (ll i = 0; i < n; i++)
- // {
- // cin >> v[i];
- // if (v[i] == t)
- // flag++;
- // }
- // for (ll i = 0; i < n; i++)
- // {
- // if (v[i] == t)
- // continue;
- // if (mt.find(t - v[i]) != mt.end() and flag)
- // {
- // cnt++, flag--;
- // mt.erase(mt.find(t - v[i]));
- // }
- // else
- // mt.insert(v[i]);
- // }
- // cout << max(cnt, 0ll) << " " << mt.size() + flag << '\n';
- // }
- int main()
- {
- Warding();
- int t = 1;
- cin >> t;
- while (t--)
- {
- solve();
- }
- Time
- }
Advertisement
Add Comment
Please, Sign In to add comment