Skip to content

Instantly share code, notes, and snippets.

@AashishNandakumar
Last active September 6, 2024 09:07
Show Gist options
  • Save AashishNandakumar/7123671e8246f64f3303cdce578a7bde to your computer and use it in GitHub Desktop.
Save AashishNandakumar/7123671e8246f64f3303cdce578a7bde to your computer and use it in GitHub Desktop.
September 6th 2024 Questions
def forbidden_integer():
n, k, x = map(int, input().split())
if x != 1:
# We can always form n using 1's
print("YES")
print(n)
print(" ".join(["1"] * n))
elif n > 1 and k > 1:
# We can for n using 2's and possibly one 3
if n % 2 == 0:
print("YES")
print(n // 2)
print(" ".join(["2"] * (n // 2)))
elif k > 2:
print("YES")
print(n // 2)
print("3 " + " ".join(["2"] * (n // 2 - 1)))
else:
print("NO")
else:
print("NO")
t = int(input())
for _ in range(t):
forbidden_integer()
def desorting():
n = int(input())
a = list(map(int, input().split()))
# logic
min_difference = float("inf")
for i in range(n - 1):
if a[i] > a[i + 1]:
return 0
min_difference = min(min_difference, a[i + 1] - a[i])
return (min_difference // 2) + 1
t = int(input())
for _ in range(t):
print(desorting())
def array_colouring():
n = int(input())
a = list(map(int, input().split()))
# logic
even_sum = sum(x for x in a if x % 2 == 0)
odd_sum = sum(x for x in a if x % 2 != 0)
return "YES" if even_sum % 2 == odd_sum % 2 else "NO"
t = int(input())
for _ in range(t):
print(array_colouring())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment