about summary refs log tree commit diff
path: root/codechef/queue2.py
blob: 7f46079231c5244745cf3e8930b59b8ab70b5169 (plain) (blame)
1
2
3
4
5
6
7
8
#!/usr/bin/env python3
for _ in range(int(input())):
    n, m, k, l = map(int, input().split())
    m *= l
    d = {0: m, k: m - k + n*l}
    for i, a in enumerate(sorted(map(int, input().split()))):
        d[a] = m - a + i*l
    print(min(d.values()) + l)