Daily AtCoder # 46 in Python

Introduction

Last time

#46 ABC131-D

** Thoughts ** Sort by $ B_i $ and calculate the time required to get the job done. Change the flag when the time limit is exceeded.

n = int(input())
ab = [list(map(int,input().split())) for _ in range(n)]

ab.sort(key=lambda x: x[1])
t = 0
flag = True
for i in range(n):
    t += ab[i][0]
    if t > ab[i][1]:
        flag = False
if flag:
    print('Yes')
else:
    print('No')

ARC093-C

** Thoughts ** In terms of the size of NO(N^2)Cannot be passed. So wellO(N)I will do it. Since the coordinates of the start and goal are 0, add 0 to the left and right. d|a[i+1]-a[i]|、0\leq i \leq N, D sumsum(d)Let be s. Then, tourist spotsiWhen you skips+|a[i+1]-a[i-1]|-(|a[i]-a[i-1]|+|a[i+1]-a[i]|It will be.

n = int(input())
a = list(map(int,input().split()))

a.insert(0,0)
a.append(0)
d = [abs(a[i]-a[i+1]) for i in range(n+1)]
s = sum(d)
for i in range(1,n+1):
    print(s+abs(a[i-1]-a[i+1])-(abs(a[i-1]-a[i])+abs(a[i]-a[i+1])))

Summary

I thought about the second question a little. I realized that I had to reduce the amount of calculation because N was large, but I couldn't reduce it well. See you again, good night.

Recommended Posts

Daily AtCoder # 36 in Python
Daily AtCoder # 2 in Python
Daily AtCoder # 32 in Python
Daily AtCoder # 6 in Python
Daily AtCoder # 18 in Python
Daily AtCoder # 53 in Python
Daily AtCoder # 33 in Python
Daily AtCoder # 7 in Python
Daily AtCoder # 24 in Python
Daily AtCoder # 37 in Python
Daily AtCoder # 8 in Python
Daily AtCoder # 42 in Python
Daily AtCoder # 17 in Python
Daily AtCoder # 54 in Python
Daily AtCoder # 11 in Python
Daily AtCoder # 47 in Python
Daily AtCoder # 13 in Python
Daily AtCoder # 45 in Python
Daily AtCoder # 30 in Python
Daily AtCoder # 40 in Python
Daily AtCoder # 10 in Python
Daily AtCoder # 5 in Python
Daily AtCoder # 28 in Python
Daily AtCoder # 39 in Python
Daily AtCoder # 19 in Python
Daily AtCoder # 52 in Python
Daily AtCoder # 3 in Python
Daily AtCoder # 14 in Python
Daily AtCoder # 50 in Python
Daily AtCoder # 26 in Python
Daily AtCoder # 4 in Python
Daily AtCoder # 43 in Python
Daily AtCoder # 29 in Python
Daily AtCoder # 22 in Python
Daily AtCoder # 49 in Python
Daily AtCoder # 27 in Python
Daily AtCoder # 25 in Python
Daily AtCoder # 12 in Python
Daily AtCoder # 48 in Python
Daily AtCoder # 23 in Python
Daily AtCoder # 34 in Python
Daily AtCoder # 51 in Python
Daily AtCoder # 31 in Python
Daily AtCoder # 46 in Python
Daily AtCoder # 35 in Python
Daily AtCoder # 9 in Python
Daily AtCoder # 44 in Python
Daily AtCoder # 41 in Python
Atcoder ABC164 A-C in Python
atCoder 173 Python
Python Input Note in AtCoder
Atcoder ABC167 A-D in Python
Atcoder ABC165 A-D in Python
Atcoder ABC169 A-E in Python
AtCoder ABC177 A-D in python
Solve Atcoder ABC169 A-D in Python
[Python] Basic knowledge used in AtCoder
Quadtree in Python --2
Python in optimization
CURL in python
Metaprogramming in Python