Here is the link to the contest. All problems are from Codeforces' problemset.
A. Split the Set
Since the sum of numbers in one pair has to be odd; in each pair, there has to be exactly one odd and one even number. Therefore; for the whole array, the count of odd numbers should be equal to the count of even numbers.
And, because the array size is $$$2n$$$, there has to be $$$n$$$ amount of odd numbers and $$$n$$$ amount of even numbers in the array. We can verify the answer by just checking the count of odd numbers too.
import sys
input = lambda: sys.stdin.readline().rstrip()
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
odd_count = 0
even_count = 0
for num in a:
if num & 1:
odd_count += 1
else:
even_count += 1
print('Yes' if odd_count == even_count else 'No')
B. Fasika and Children
For every child the number of turns that they are going to go through is $$$ceil(a_i/m)$$$, so we need to find the child who have to go through the maximum number of turns and if two childs are going to go through the same number of turns the one who is at the last index will finish later.
from math import ceil
import sys
input = sys.stdin.readline
def solve():
n,m = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
max_ceil = ceil(a[0]/m)
for i in range(1, n):
cur_ceil = ceil(a[i]/m)
if cur_ceil >= max_ceil:
max_ceil = cur_ceil
ans = i
print(ans + 1)
solve()
C. Permutation Sorting
For every $$$k$$$ such that $$$a_i=k$$$, $$$a_j=k+1$$$ and $$$i$$$>$$$j$$$ we have to choose $$$x$$$=$$$k$$$+$$$1$$$ at least once for these elements to be in the correct order. It is easy to see that if we choose all such $$$x$$$=$$$k$$$+$$$1$$$ for all such $$$k$$$ exactly once in any order, we will get the identity permutation.
import sys
def solve():
n = int(sys.stdin.readline().strip())
nums = list(map(int, sys.stdin.readline().strip().split()))
prev = set()
ans = 0
for num in nums:
if num + 1 in prev:
ans += 1
prev.add(num)
return ans
t = int(sys.stdin.readline().strip())
for _ in range(t):
print(solve())
D. Candies in the Box
Let's consider the number of candies remaining at the evening of each day for some selected $$$(k1)$$$. Let $$$ai$$$ candies remain on day $$$i$$$. If Vasya will use another number $$$(k2 > k1)$$$ we will have less candies on the first day: $$$(b1 < a1)$$$. So Petya will eat no more candies than in the first case (for $$$k1$$$), but in the next day the number of candies will be not greater than in the first case (if $$$(n1 > n2)$$$ then $$$(n1 - n1 / 10 ≥ n2 - n2 / 10)$$$). The same way, including that $$$(k2 > k1$$$) at the evening of the second day we get $$$(b2 < a2)$$$ and so on. In general, for each $$$i$$$ we have $$$(bi < ai)$$$, so Petya will eat no more candies than in the first case in total. It means that Vasya will eat not less candies than in the first case. That means for a given $$$k1$$$ if Vasya could eat at least half of the candies, we should look for another $$$k2$$$ which is less than $$$k1$$$. And we can use binary search for that. Since Vasya eats $$$k$$$ candies and Petya eats $$$10\%$$$ of candies, its amount decreases exponentially, so there will be only a few days before all the candies will be eaten. Formally the time complexity of the solution is $$$O((\log_k n) \cdot (\log_{10} n))$$$ with constant space complexity.
def check_k(n, k):
eaten = 0
curr_candies = n
while curr_candies > 0:
k = min(k, curr_candies)
eaten += k
curr_candies -= k
curr_candies -= curr_candies // 10
return eaten * 2 >= n
n = int(input())
k = n
left, right = 1, n
while left <= right:
mid = left + (right - left) // 2
if check_k(n, mid):
k = mid
right = mid - 1
else:
left = mid + 1
print(k)
E. Beef in M.A.A.D City
Since Drake can predict Kendrick's moves, the only way Kendrick can catch Drake is if there is only one option for Drake to move. If Drake has multiple options, Kendrick will never catch him. The city has a tree-like structure with one extra edge, meaning there is one cycle inside the city. If Drake reaches the cycle faster than Kendrick, Kendrick will never catch Drake. Otherwise, Kendrick will catch him. We can implement this by using topological sort to get all the nodes inside the cycle. After identifying all the nodes in the cycle, we can use multi-source BFS to determine who reaches any of the nodes inside the cycle first.
t = int(input())
for _ in range(t):
n,m,v = list(map(int,input().split()))
graph = [[] for i in range(n)]
degree = [0 for i in range(n)]
for i in range(n):
a,b = list(map(int,input().split()))
graph[a - 1].append(b - 1)
graph[b - 1].append(a - 1)
degree[a - 1] += 1
degree[b - 1] += 1
que = deque()
for i in range(len(degree)):
if degree[i] == 1:
que.append(i)
order = []
while que:
cur = que.popleft()
order.append(cur)
for child in graph[cur]:
degree[child] -= 1
if degree[child] == 1:
que.append(child)
order = set(order)
color = [0 for i in range(n)]
pos = 0
color[m - 1] = 1
color[v - 1] = 2
que.append(m - 1)
que.append(v - 1)
while que:
size = len(que)
for i in range(size):
cur = que.popleft()
for neigh in graph[cur]:
if color[neigh] == 0:
que.append(neigh)
color[neigh] = color[cur]
pos = 0
for i in range(len(graph)):
if i not in order and color[i] == 2:
pos = 1
if pos and v != m:
print("YES")
else:
print("NO")