from collections import defaultdict
for _ in range(int(input())):
n, m = map(int, input().split())
a: list[int] = list(map(int, input().split()))
c = defaultdict(int)
for ai in a:
c[ai] += 1
ans: int = -1
for k1, c1 in c.items():
k2 = k1 + 1
if k2 not in c:
ans = max(ans, k1 * min(m // k1, c1))
continue
c2 = c[k2]
for pc1 in range(1, c1 + 1):
pv1: int = k1 * pc1
rem: int = m - pv1
if rem < 0:
break
ans = max(ans, pv1 + k2 * min(c2, (rem // k2)))
assert ans <= m
print(ans)
My solution
def suneet_win(su1: int, su2: int, sl1: int, sl2: int) -> bool:
if su1 > sl1:
return su2 >= sl2
elif su1 == sl1:
return su2 > sl2
else:
return False
for _ in range(int(input())):
a1, a2, b1, b2 = map(int, input().split())
# [(Suneet 1, Suneet 2, Slavic 1, Slavic 2)]
# Beacuse of the symmetry, I can skip thinking about (a2, a1, ...) types
# and double the ans in the end.
combs: list[tuple[int, int, int, int]] = []
combs.append((a1, a2, b1, b2))
combs.append((a1, a2, b2, b1))
ans: int = 0
for comb in combs:
if suneet_win(*comb):
ans += 1
print(ans * 2)
Codeforces Round 964 (Div. 4) Editorial
The only direction it has is
For each test case, we can brute force through all possible games (there are only four of them) and calculate who is the winner of the game by simulating the game.
I was overthinking.
I'm not sure why this brute force problem has 1000
rating. Maybe people overthought same as me.
Rice 400 Nori 100 Bagels 500 Protein shake 100 Nimono 600 Yogurt 300
Total 2000 kcal
pull-ups, push-ups
MUST:
TODO: