Codey and Spam
https://www.hackerrank.com/contests/codenection-2024-preliminary-round-closed-category/challenges/cn24-3
Last updated
https://www.hackerrank.com/contests/codenection-2024-preliminary-round-closed-category/challenges/cn24-3
Last updated
Codey is too excited for CodeNection 2024! It wanted to spam a series of lines arranged in a triangle on the Discord server. The height (vertex) of the triangle is n
, and it contains 2n-1
lines.
Example of n = 3
containing 5
lines:
CODENECTION
CODENECTIONCODENECTION
CODENECTIONCODENECTIONCODENECTION
CODENECTIONCODENECTION
CODENECTION
However, Zoey will kick Codey out immediately if it spam at least x
CODENECTION
word consecutively. How many lines can Codey spam before Zoey kicks it out of the server?
The first line contains two integers, n
and x
, where n
represents the height of the triangle and x
represents the maximum number of consecutive CODENECTION
allowed before Zoey kicks Codey out.
Output an integer representing the maximum number of lines Codey can spam before getting kicked out.
6
n, m = map(int, input().strip().split())
total_spam = 0
lines = 0
steps = 1
while steps <= n:
total_spam += steps
lines += 1
if total_spam >= m:
break
steps += 1
if total_spam < m:
steps = n - 1
while total_spam < m and steps > 0:
total_spam += steps
lines += 1
steps -= 1
print(lines)