I got up early today, so I will write an article.
** Thoughts ** Take min and divide
a, b, c = map(int,input().split())
if a > b:
ans = c // b
print(ans)
else:
ans = c // a
print(ans)
** Thoughts ** Since Q is small, you can turn it with for
n, q = map(int,input().split())
lrt = [list(map(int,input().split())) for _ in range(q)]
a = [0] * n
for i in range(q):
a[lrt[i][0]-1:lrt[i][1]] = [lrt[i][2]] * (lrt[i][1]-lrt[i][0]+1)
for i in range(n):
print(a[i])
** Thoughts ** If you use slices, you will probably TLE, so use the cumulative sum. It's easier to use numpy, so I'll use numpy.
import numpy as np
n, k = map(int,input().split())
a = list(map(int,input().split()))
a = np.cumsum(a)
a = np.append(0,a) #np.If it is cumsum, 0 will not be added, so append
ans = 0
for i in range(n):
if i + k >= n + 1:
break
ans += a[i+k]-a[i]
print(ans)
D cannot be done. see you.
Recommended Posts