-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1497B_Marrays.cpp
More file actions
42 lines (42 loc) · 974 Bytes
/
Copy path1497B_Marrays.cpp
File metadata and controls
42 lines (42 loc) · 974 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <bits/stdc++.h> //Problem-
using namespace std;
#define ll long long
int main()
{
ios::sync_with_stdio(false);
cin.tie(nullptr);
ll t;
cin >> t;
while (t--)
{
ll n, m, i, ans = 0;
cin >> n >> m;
vector<ll> v(n);
map<ll, ll> freq;
for (i = 0; i < n; i++)
{
cin >> v[i];
freq[(v[i] % m)]++;
}
for (i = 1; i <= m / 2; i++)
{
if (freq[i] > 0 && freq[m - i] > 0)
{
ll x = min(freq[i], freq[m - i]);
freq[i] -= x;
freq[m - i] -= x;
ll y = max(freq[i], freq[m - i]);
ans++;
if (y > 1)
ans += y - 1;
}
else if (freq[i] > 0 || freq[m - i] > 0)
ans += max(freq[i], freq[m - i]);
}
ans += (freq[0] > 0);
cout << ans << endl;
}
return 0;
}