20240724

1995A. Diagonals

It took me some time to realize that diagonals in this problem does not include ones from top-left to bottom-right.

A diagonal is the set of cells for which the value i + j is the same.

To minimize the number of occupied diagonals, we should place chips from the longest diagonals to the shortest.

first diagonal => i + j = n => n chips

second/third diagonals => i + j = n - 1 => 2 * (n - 1) chips

2 * (n - 2), 2 * (n - 3), …

def solve(n: int, k: int) -> int:
    if k == 0:
        return 0
    if k <= n:
        return 1

    count = 1
    k -= n
    for i in range(n - 1, 0, -1):
        count += 1
        k -= i
        if k <= 0:
            return count
        count += 1
        k -= i
        if k <= 0:
            return count
    return count


for _ in range(int(input())):
    n, k = map(int, input().split())
    print(solve(n, k))

1995B1. Bouquet (Easy Version)

It's new to me that fixing the count of x will determine the count of x + 1.

max_bouq: int = min(m // x, sm_count) is also new to me. Hope my brain holds it somewhere.

from collections import defaultdict


def solve():
    n, m = map(int, input().split())
    a = list(map(int, input().split()))

    counter = defaultdict(int)
    for x in a:
        counter[x] += 1

    ans = 0
    for x in counter.keys():
        # case 1
        sm_count: int = counter[x]
        max_bouq: int = min(m // x, sm_count)
        ans = max(ans, max_bouq * x)

        if x + 1 not in counter:
            continue

        # case 2
        la_count: int = counter[x + 1]
        for sm in range(1, sm_count + 1):
            if sm * x > m:
                break
            rem_mn: int = m - sm * x
            tmp_ans = min(rem_mn // (x + 1), la_count) * (x + 1) + sm * x
            ans = max(tmp_ans, ans)
    print(ans)


for _ in range(int(input())):
    solve()

1988B. Make Majority

"""memo
n       a =  [1]
n - 1   a -> [0, 1, 0, 1, 1] c1 > c0

is it possible to make c0 >= c1 -> c1 > c0 ?
[1, 0, 0, 0, 1, 1] => [1, 0, 1, 1] by choosing l = 1, r = 4

what is the minimum number of 0s I can make? => The number of 0s sections
"""

for _ in range(int(input())):
    n: int = int(input())
    a: list[int] = list(map(int, list(input())))

    c1: int = sum(a)
    c0: int = 0
    prev = None
    for i in range(n):
        if a[i] == 0 and a[i] != prev:
            c0 += 1
        prev = a[i]
    if c1 > c0:
        print("YES")
    else:
        print("NO")

Ketone 10 mg/dl

Chipotle Keto Bowl 50g Bacon Egg 0g Salad 10g Cheese 5g

Total carbohydrate 65g

pull ups push ups 6k run


MUST:

TODO:


index 20240723 20240725