January 2022 enrollments are closed and the course commences on 8th of January, 2022. For future cohorts

NON-DIVISIBLE-SUBSET Solution

/*
*  Author: Arpit Bhayani
*  https://arpitbhayani.me
*/
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <climits>
#include <deque>
#include <iostream>
#include <list>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <vector>

#define ll long long

#define MIN(a, b) a < b ? a : b
#define MAX(a, b) a > b ? a : b

using namespace std;

int i = 0;
char ch;
while((ch = getchar()) != '\n') {
str[i++] = ch;
}
str[i] = '\0';
return i;
}

map<ll int, ll int> m;
ll int arr;
int main(int argc, char *argv[]) {
ll int n, k;
scanf("%lld%lld", &n, &k);

for(int i = 0 ; i < n ; i++) {
cin >> arr[i];
if(arr[i] % k == 0) {
m[arr[i] % k] = 1;
}
else {
m[arr[i] % k]++;
}
}

ll int count = m;
ll int start = 1;
ll int end = k - 1;
while(start < end) {
count += MAX(m[start], m[end]);
start++;
end--;
}

if(k % 2 == 0 && m.find(k/2) != m.end()) {
count++;
}

printf("%lld\n", count);

return 0;
}