forked from abeaumont/competitive-programming
-
Notifications
You must be signed in to change notification settings - Fork 0
/
a.cc
53 lines (51 loc) · 1014 Bytes
/
a.cc
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
43
44
45
46
47
48
49
50
51
52
53
// https://codingcompetitions.withgoogle.com/codejam/round/0000000000201900/00000000002017f4
#include <bits/stdc++.h>
using namespace std;
using vi=vector<int>;
int main() {
int T,n,p,x;
cin>>T;
for(int t=1;t<=T;t++){
cin>>n>>p;
vi a(p);
for (int i=0;i<n;i++){
cin>>x;
a[x%p]++;
}
int c=a[0];
if(p==2){
c+=a[1]/2;
a[1]-=(a[1]/2)*2;
} else if(p==3){
int k=min(a[1],a[2]);
c+=k;
a[1]-=k;
a[2]-=k;
k=max(a[1],a[2]);
if(a[1])a[1]-=(k/3);
if(a[2])a[2]-=(k/3);
c+=(k-1)/3;
} else{
c+=a[2]/2;
a[2]=a[2]%2;
int k=min(a[1],a[3]);
c+=k;
a[1]-=k;
a[3]-=k;
if (a[2]&&max(a[1],a[3])>=2) {
c++;
a[2]=0;
if(a[1])a[1]-=2;
else a[3]-=2;
}
k=max(a[1],a[3]);
c+=k/4;
if(a[1])a[1]-=(k/4)*4;
else a[3]-=(k/4)*4;
}
int s=0;
for(int i=1;i<p;i++) s+=a[i];
if(s)c++;
printf("Case #%d: %d\n",t,c);
}
}