Mim needs to select exactly K members at a game studio whose combined rating GCD is divisible by G, maximizing the total pairwise rating spread among them.
What your program reads
Line1: N. Line2: N integers. Line3: Q. Next Q lines: K G.
What your program prints
Max spread sum, or -1.
Limits
1 ≤ N,Q ≤ 2000
Example input
5 4 8 6 12 3 1 3 2
Expected output
24
main.c
Your work is saved in this browser as you type.
Loading editor…
Input for Run
Run tries your code on the input above and shows what it prints. Submit checks your output against every test, including hidden ones.
Shortcut: Ctrl + Enter sends it to the judge.