Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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 flag)
- {
- if (t - v[i] == t)
- {
- if (flag >= 2)
- {
- flag -= 2;
- cnt += 3;
- m[t] -= 2;
- continue;
- }
- else
- continue;
- }
- cnt += 3, flag--;
- m[t - v[i]]--;
- }
- else if (v[i] != t)
- m[v[i]]++;
- }
- if (t + t == t)
- cnt += flag / 3 * 3;
- cout << max(cnt / 3, 0ll) << " " << n - cnt << '\n';
- }
Advertisement
Add Comment
Please, Sign In to add comment