# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1188624 | krittaphot | Rabbit Carrot (LMIO19_triusis) | Pypy 3 | 152 ms | 51360 KiB |
def min_modifications(n, m, heights):
current_height = 0 # เริ่มจากพื้น
changes = 0 # นับจำนวนครั้งที่ต้องแก้ไขเสา
for h in heights:
if h - current_height > m:
# กระโดดขึ้นไม่ถึง -> ต้องปรับเสานี้
changes += 1
# ปรับเสานี้ลงให้เท่ากับระดับที่กระโดดได้
current_height = current_height + m
else:
# กระโดดถึง (ขึ้นไม่เกิน M หรือกระโดดลงได้)
current_height = h
return changes
# ----------- รับ Input จากผู้ใช้ ------------
# ตัวอย่าง input:
# 3 300
# 700
# 1000
# 1300
n, m = map(int, input().split()) # จำนวนเสา และระยะกระโดดสูงสุด
heights = [int(input()) for _ in range(n)] # ความสูงของเสาแต่ละต้น
# เรียกใช้ฟังก์ชันและพิมพ์ผลลัพธ์
print(min_modifications(n, m, heights))
Compilation message (stdout)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |