Solve ABC037 A ~ C in Python

Introduction

I got up early today, so I will write an article.

A problem

Problem

** 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)

B problem

Problem

** 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])

C problem

Problem

** 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)

Summary

D cannot be done. see you.

Recommended Posts

Solve ABC036 A ~ C in Python
Solve ABC037 A ~ C in Python
Solve ABC175 A, B, C in Python
Solve ABC163 A ~ C with Python
ABC166 in Python A ~ C problem
Solve ABC162 A ~ C with Python
Solve ABC167 A ~ C with Python
Solve ABC158 A ~ C with Python
Solve ABC169 in Python
Solve Atcoder ABC176 (A, B, C, E) in Python
Solve ABC165 A, B, D in Python
Solve ABC176 E in Python
Solve ABC175 D in Python
ABC127 A, B, C Explanation (python)
Solve ABC166 A ~ D with Python
Solve Atcoder ABC169 A-D in Python
ABC128 A, B, C commentary (python)
ABC 157 D --Solve Friend Suggestions in Python!
Algorithm in Python (ABC 146 C Binary Search
[AtCoder] Solve ABC1 ~ 100 A problem with Python
I wanted to solve ABC159 in Python
Solve AtCoder ABC168 with python (A ~ D)
Solve ABC168D in Python
Solve ABC167-D in Python
Solve ABC146-C in Python
Next Python in C
Solve ABC098-C in Python
Solve ABC159-D in Python
C API in Python 3
ABC147 C --HonestOrUnkind2 [Python]
Solve ABC160-E in Python
[AtCoder] Solve A problem of ABC101 ~ 169 with Python
Call a Python script from Embedded Python in C ++ / C ++
I tried adding a Python3 module in C
Challenge AtCoder (ABC) 164 with Python! A ~ C problem
Extend python in C ++ (Boost.NumPy)
Take a screenshot in Python
Solve AtCoder ABC166 with python
Create a dictionary in Python
ABC163 C problem with python3
AtCoder ABC 178 Python (A ~ E)
Atcoder ABC164 A-C in Python
ABC memorandum [ABC163 C --managementr] (Python)
AtCoder ABC 176 Python (A ~ E)
Atcoder ABC167 A-D in Python
Solve Wooldridge exercises in Python
Binary search in Python / C ++
Make a bookmarklet in Python
Atcoder ABC165 A-D in Python
Atcoder ABC166 A-E in Python
AtCoder ABC 182 Python (A ~ D)
Solve optimization problems in Python
Draw a heart in Python
ABC188 C problem with python3
Solve AtCoder ABC 186 with Python
ABC187 C problem with python
Atcoder ABC169 A-E in Python
AtCoder ABC177 A-D in python
Try to make a Python module in C language
Try embedding Python in a C ++ program with pybind11
Write a binary search in Python