I didn't plan to work hard today, but did somehow.
It's been a while since I solved this in the contest, and it took me some time to remember how I approached this.
If there are multiple indices with the same value, we can use the corresponding lexicographically smallest character from c. The others will be discarded.
s = “abc”
ind = [0, 0, 0]
c = “def” -(rearrange)-> “fed”
result = “dbc” ( < “ebc” or “fbc”)
ind
to group the same valuesc
to update s
with the
lexicographically smallest values.for _ in range(int(input())):
n, m = map(int, input().split())
s: list[str] = list(input())
ind: list[int] = list(map(int, input().split()))
ind.sort()
c = input()
c: list[str] = sorted(c)
prev_ind = None
ci = 0
for i in range(m):
if ind[i] != prev_ind:
s[ind[i] - 1] = c[ci]
ci += 1
prev_ind = ind[i]
print("".join(s))
1 <= a, b, m <= 10 ** 18 -> need to solve in O(1)
To maximize the number of fireworks -> fires both of the fireworks
at the same time (at a
* b
minutes for any
a
and b
).
When firing both fireworks, the number of fireworks that can be seen
at m
is m // a + 1
(including the starting
point). Same goes for b
result: (m // a + 1) + (m // b + 1)
for _ in range(int(input())):
a, b, m = map(int, input().split())
# num of 1st fireworks that can exist at the same time
first: int = m // a + 1
# num of 2nd fireworks that can exist at the same time
second: int = m // b + 1
res: int = first + second
print(res)
Kombucha 200 Hamburgers 700 Vietnamese quisine 800 (unexpected) Protein shake 200 Meat stick 100 Chicken breast
Total 2200 kcal
TODO: