Статья Автор: Абаньшина Саша

зачет

полный граф
n, m = map(int, input().split())
l1 = [0] * n
l = []
t = True
for i in range(n):
    l.append(l1.copy())
    l[i][i] = 1
for i in range(m):
    x, y = map(int, input().split())
    l[x - 1][y - 1] = 1
    l[y - 1][x - 1] = 1
for i in range(n):
    for j in range(n-i-1):
        if l[i][j+i+1] == 0:
            t = False
if t:
    print("YES")
else:
  print("NO")

коровы в стойла
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
left = 0
right = a[-1] - a[0] + 1
while left < right:
    mid = (left + right)//2
    cows = 1
    last = a[0]
    for cur in a[1:]:
        if cur - last > mid:
            cows += 1
            last = cur
    if cows >= k:
        left = mid+1
    else:
        right = mid
print(left)

отрезок с макс суммой
n = int(input())
a = [0]
sm = 0
for _ in range(n):
  sm += int(input())
  a += [sm]
jb, ib, im = 0, 0, -1
for m in range(len(a) - 1):
  if im == -1 or a[m] <= a[im]:
    im = m
  if a[m+1] - a[im] > a[jb] - a[ib]:
    ib, jb = im, m + 1
print(ib + 1)
print(jb)

шарики
a = input().split()
s = ""
n = int(a[0])
s = ''.join(a[1:])
ans = 0
while True:
    f = False
    for i in range(0, 10):
        p1 = s.find(str(i)+str(i)+str(i))
        
        if p1 != -1:
            p = p1
            while p < n and s[p] == str(i):
                p += 1
            s = s[:p1] + s[p:]
            ans += p - p1
            n = len(s)
            f = True
            break
    
    if not f:
        break
print(ans)

раздача подарков
n, k = map(int, input().split())
a = [i for i in range(1, n+1)]
c = 0
ans = []
for j in range(n):
  c = (c + k - 1) % len(a)
  ans += [a.pop(c)]
print(*ans)

очень легкая 
n, x, y = map(int, input().split())
l = 0
r = max(x, y) * ( n - 1)
while r - l > 1:
  m = (l + r) // 2
  if ( m // x + m // y) >= n -1:
    r = m
  else:
    l= m
print(r + min(x, y))

количество чисел равное искомому
n = int(input())
a = list(map(int, input().split()))
k = int(input())
b = list(map(int, input().split()))
for x in b:
    l, r = -1, n
    while r - l > 1:
        m = (r + l) // 2
        if a[m] >= x:
            r = m
        else:
            l = m
    l1 = -1
    r1 = n
    while r1 - l1 > 1:
        m = (r1 + l1) // 2
        if a[m] <= x:
            l1 = m
        else:
            r1 = m
    if l == l1 and r == r1:
        print(0)
        continue
    if r == l1:
        print(1)
    else:
        print(l1 - r + 1)
Пропустить Навигационные Ссылки.
Чтобы оставить комментарий нужна авторизация
Печать