Skip to content

Commit 48e9809

Browse files
committed
🥺chore
1 parent dee23cb commit 48e9809

File tree

3 files changed

+74
-0
lines changed

3 files changed

+74
-0
lines changed

abc143/d/_main.py

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
#!usr/bin/env python3
2+
from collections import defaultdict, deque, Counter, OrderedDict
3+
from bisect import bisect_left, bisect_right
4+
from functools import reduce, lru_cache
5+
from heapq import heappush, heappop, heapify
6+
7+
import itertools
8+
import math, fractions
9+
import sys, copy
10+
11+
def L(): return sys.stdin.readline().split()
12+
def I(): return int(sys.stdin.readline().rstrip())
13+
def SL(): return list(sys.stdin.readline().rstrip())
14+
def LI(): return [int(x) for x in sys.stdin.readline().split()]
15+
def LI1(): return [int(x) - 1 for x in sys.stdin.readline().split()]
16+
def LS(): return [list(x) for x in sys.stdin.readline().split()]
17+
def R(n): return [sys.stdin.readline().strip() for _ in range(n)]
18+
def LR(n): return [L() for _ in range(n)]
19+
def IR(n): return [I() for _ in range(n)]
20+
def LIR(n): return [LI() for _ in range(n)]
21+
def LIR1(n): return [LI1() for _ in range(n)]
22+
def SR(n): return [SL() for _ in range(n)]
23+
def LSR(n): return [LS() for _ in range(n)]
24+
25+
def perm(n, r): return math.factorial(n) // math.factorial(r)
26+
def comb(n, r): return math.factorial(n) // (math.factorial(r) * math.factorial(n-r))
27+
28+
def make_list(n, *args, default=0): return [make_list(*args, default=default) for _ in range(n)] if len(args) > 0 else [default for _ in range(n)]
29+
30+
dire = [[1, 0], [0, 1], [-1, 0], [0, -1]]
31+
dire8 = [[1, 0], [1, 1], [0, 1], [-1, 1], [-1, 0], [-1, -1], [0, -1], [1, -1]]
32+
alphabets = "abcdefghijklmnopqrstuvwxyz"
33+
ALPHABETS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
34+
MOD = 1000000007
35+
INF = float("inf")
36+
37+
sys.setrecursionlimit(1000000)
38+
39+
def main():
40+
N = I()
41+
L = sorted(LI())
42+
ans = 0
43+
44+
for i in range(N):
45+
for j in range(i+1, N):
46+
a, b = L[i], L[j]
47+
# print(L[j+1:], abs(a - b), a+b, bisect_left(L[j+1:], abs(a - b)), bisect_left(L[j+1:], a + b))
48+
ans += bisect_left(L[j+1:], a + b) - bisect_left(L[j+1:], abs(a - b))
49+
50+
print(ans)
51+
52+
if __name__ == '__main__':
53+
main()

abc143/d/main.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,16 @@ def make_list(n, *args, default=0): return [make_list(*args, default=default) fo
3838

3939
def main():
4040
N = I()
41+
L = sorted(LI())
42+
ans = 0
43+
44+
for i in range(N):
45+
k = i
46+
for j in range(i+1, N):
47+
while k < N and L[k] < L[i] + L[j]: k += 1
48+
ans += k - (j + 1)
49+
50+
print(ans)
4151

4252
if __name__ == '__main__':
4353
main()

abc176/c/main.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,17 @@ def make_list(n, *args, default=0): return [make_list(*args, default=default) fo
3838

3939
def main():
4040
N = I()
41+
A = LI()
42+
43+
s = 0
44+
high = 0
45+
for ai in A:
46+
if ai < high:
47+
s += high - ai
48+
else:
49+
high = ai
50+
51+
print(s)
4152

4253
if __name__ == '__main__':
4354
main()

0 commit comments

Comments
 (0)