Set 106Question 12

Mahi's Constrained Team Spread

ExtremeWritten in CMust finish in 5 seconds

Mahi needs to select exactly K members at a research lab 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.

Mahi's Constrained Team Spread · DIU ContestHub