Skip to content

Commit 1852858

Browse files
Add files via upload
1 parent fdf14d6 commit 1852858

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed

Other_Tasks/CF2112_A_Race.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
for _ in range(int(input())):
2+
a, x, y = map(int, input().split())
3+
x, y = min(x, y), max(x, y)
4+
5+
if x <= a and a <= y:
6+
print("NO")
7+
else:
8+
print("YES")
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
for _ in range(int(input())):
2+
n = int(input())
3+
arr = list(map(int, input().split()))
4+
5+
done = False
6+
for a, b in zip(arr, arr[1:]):
7+
if abs(a - b) <= 1:
8+
print(0)
9+
done = True
10+
break
11+
else:
12+
increasing = all(a < b for a, b in zip(arr, arr[1:]))
13+
decreasing = all(a > b for a, b in zip(arr, arr[1:]))
14+
if increasing or decreasing:
15+
print(-1)
16+
else:
17+
print(1)
18+
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
for _ in range(int(input())):
2+
n = int(input())
3+
arr = list(sorted(map(int, input().split())))
4+
maxi = max(arr)
5+
ans = 0
6+
7+
for i in range(n):
8+
a = arr[i]
9+
top = 0 # exclusive
10+
bottom = n - 1 # exclusive
11+
for j in range(i + 1, n):
12+
b = arr[j]
13+
while top < n and arr[top] < a + b:
14+
top += 1
15+
while bottom > j and arr[bottom] > maxi - a - b:
16+
bottom -= 1
17+
bottom = max(bottom, j)
18+
19+
if top > bottom:
20+
ans += top - bottom - 1
21+
22+
print(ans)

0 commit comments

Comments
 (0)