Here is the mashup link (the problems are from Codeforces' problem set).
A. Community Education Division
For this problem you just need to implement what it asks you. To be able to implement it you need to know about the "if" statement.
t = int(input())
for _ in range(t):
rating = int(input())
if rating >= 1900:
print("Division 1")
elif 1600 <= rating <= 1899:
print("Division 2")
elif 1400 <= rating <= 1599:
print("Division 3")
else:
print("Division 4")
B. Encrypted Postcards
Note that during encryption, only characters different from $$$c$$$ are added after the character $$$c$$$. However, when the character $$$c$$$ is encrypted with different characters, another $$$c$$$ character is added to the string.
This means that for decryption, we only need to read the characters of the string after $$$c$$$ until we find the first character equal to $$$c$$$. It signals the end of the block of characters that will be converted to the character $$$c$$$ during decryption.
To decrypt the entire string, we decrypt the first character $$$s1$$$. Let the next occurrence of the character $$$s1$$$ be at position $$$pos1$$$. Then the next character of the original string is $$$s_{pos1+1}$$$. We apply the same algorithm to find the next paired character and so on.
T = int(input())
for _ in range(T):
n = int(input())
s = input()
new_string = []
l = 0
r = 0
while r < len(s):
if s[l] == s[r] and l != r:
new_string.append(s[l])
r += 1
l = r
else:
r += 1
ans = "".join(new_string)
print(ans)
C. Gena
Let's sort AASTUs and AAiTs by skill. If AASTU with lowest skill can be matched, it is good idea to match him. It can't reduce answer size. Use AAiT with lowest skill to match.
N = int(input())
aastu = sorted(map(int, input().split()))
M = int(input())
aait = sorted(map(int, input().split()))
pairs = 0
p1 = 0 # pointer of aastu array
p2 = 0 # pointer of aait array
while p1 < N and p2 < M:
if abs(aastu[p1] - aait[p2]) <= 1:
pairs += 1
p1 += 1
p2 += 1
elif aastu[p1] < aait[p2]:
p1 += 1
else:
p2 += 1
print(pairs)
D. Metsehafe and Enemy Aliens
Note that if the second operation were free, we would need $$$\lceil \frac{\text{sum}}{2} \rceil$$$ operations to get rid of all the aliens. Indeed, when we kill one alien, we can kill a second alien for free with a second operation. But the second operation is not free. So we need to use the second operation as little as possible.
To do this, we need to apply ultimates (second attack) on the current largest horde by number of aliens, when the combo counter reaches the size of the largest horde. And we apply the first attack on the smallest hordes. This is so because the combo counter allows us to defeat $$$\lceil \frac{\text{sum}}{2} \rceil$$$ aliens. But since we can't apply this operation on several hordes at once, we need to keep the number of hordes on which we apply these attacks of the second type as small as possible. Then we can use the greedy algorithm described above. Formally, we need to keep a sorted array and store two pointers: pointer $$$i$$$ — to the smallest horde, $$$j$$$— to the largest horde. Until $$$i$$$ is equal to $$$j$$$: if after destroying all horde $$$i$$$ we can't kill horde $$$j$$$ with ultimates, we destroy horde $$$i$$$, increase pointer $$$i$$$ by $$$1$$$ and increase combo counter $$$x$$$ by $$$a[i]$$$. Otherwise, hit the horde $$$i$$$ so many times that the combo counter $$$x$$$ becomes $$$a[j]$$$. Then apply a second attack on horde $$$j$$$, reduce horde $$$j$$$'s counter by $$$1$$$, reduce $$$a[i]$$$, and nullify the combo counter. When $$$i$$$ becomes equal to $$$j$$$, you just need to apply the first attack the right number of times to finish with ultimates (or not if $$$a[i] =1$$$).
Total complexity $$$O(nlogn)$$$.
from math import ceil
t = int(input())
for _ in range(t):
n = int(input())
nums = sorted(map(int, input().split()))
ans = 0
cur = 0
left = 0
right = n - 1
while left < right:
cur += nums[left]
if cur >= nums[right]:
ans += nums[right] + 1
cur -= nums[right]
right -= 1
left += 1
if left == right:
cur += nums[right]
ans += (ceil(cur / 2) + 1) if cur > 1 else cur
print(ans)
E. Million the Painter
Consider when there is "??".
In how many ways can we paint "C?C"?
Consider when there is "?" at the end or beginning.
What causes the answer to be "Yes"? Of course, there cannot be adjacent segments that already have the same colour; but what else?
We can figure out that whenever two consecutive question marks appear, there are at least two ways to fill them.
But the samples lead us to ponder over cases with one single question mark: a question mark can be coloured in two different colours if it lies on the boundary of the canvas, or is between two adjacent segments of the same colour.
Putting it all together, we get a simple but correct solution.
N = int(input())
s = input()
if ("CC" in s) or ("YY" in s) or ("MM" in s):
print("No")
elif ("??" in s) or ("C?C" in s) or ("Y?Y" in s) or ("M?M" in s) or (s[0] == "?") or (s[-1] == "?"):
print("Yes")
else:
print("No")