-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathP171SUMB.cpp
More file actions
38 lines (28 loc) · 880 Bytes
/
P171SUMB.cpp
File metadata and controls
38 lines (28 loc) · 880 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
#include <bits/stdc++.h>
using namespace std;
#define For(i, a, b) for(int i = a; i <= b; i++)
#define Ford(i, a, b) for(int i = a; i >= b; i--)
#define ll long long
#define here cout<<"I am Here"<<endl;
int const maxn = 1000000;
int subsetPairNotDivisibleByK(int arr[], int N, int K){
int f[K];
memset(f, 0, sizeof(f));
for (int i = 0; i < N; i++)
f[arr[i] % K]++;
if (K % 2 == 0)
f[K/2] = min(f[K/2], 1);
int res = min(f[0], 1);
for (int i = 1; i <= K/2; i++)
res += max(f[i], f[K-i]);
return res;
}
// Driver code to test above methods
int main(){
int arr[100000], N;
int K;
cin>>N>>K;
For(i, 0, N - 1) cin>>arr[i];
cout << subsetPairNotDivisibleByK(arr, N, K);
return 0;
}