description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
You are given a string, consisting of lowercase Latin letters.
A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β "ab" and $(2, 3)$ β "ba". Letters 'a' and 'z' aren't considered neighbouring in a alphabet.
Can you rearrange the letters of a given string so that there are no ugly pairs? You can choose any order of the letters of the given string but you can't add any new letters or remove the existing ones. You can also leave the order the same.
If there are multiple answers, print any of them.
You also have to answer $T$ separate queries.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 100$) β the number of queries.
Each of the next $T$ lines contains string $s$ $(1 \le |s| \le 100)$ β the string for the next query. It is guaranteed that it contains only lowercase Latin letters.
Note that in hacks you have to set $T = 1$.
-----Output-----
Print $T$ lines. The $i$-th line should contain the answer to the $i$-th query.
If the answer for the $i$-th query exists, then print such a rearrangment of letters of the given string that it contains no ugly pairs. You can choose any order of the letters of the given string but you can't add any new letters or remove the existing ones. You can also leave the order the same.
If there are multiple answers, print any of them.
Otherwise print "No answer" for that query.
-----Example-----
Input
4
abcd
gg
codeforces
abaca
Output
cadb
gg
codfoerces
No answer
-----Note-----
In the first example answer "bdac" is also correct.
The second example showcases the fact that only neighbouring in alphabet letters are not allowed. The same letter is ok.
There are lots of valid answers for the third example.
|
t = int(input())
for i in range(t):
str = input().strip()
ascii_a = ord("a")
nums = [0] * 26
for char in str:
nums[ord(char) - ascii_a] += 1
n = 0
oddStr = ""
evenStr = ""
for i in range(len(nums)):
num = nums[i]
if num != 0:
if n % 2 == 0:
evenStr += chr(ascii_a + i) * num
else:
oddStr += chr(ascii_a + i) * num
n += 1
if n == 1:
print(str)
elif (ord(oddStr[0]) - ord(evenStr[-1])) ** 2 != 1:
print(evenStr + oddStr)
elif (ord(oddStr[-1]) - ord(evenStr[0])) ** 2 != 1:
print(oddStr + evenStr)
else:
print("No answer")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING
|
You are given a string, consisting of lowercase Latin letters.
A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β "ab" and $(2, 3)$ β "ba". Letters 'a' and 'z' aren't considered neighbouring in a alphabet.
Can you rearrange the letters of a given string so that there are no ugly pairs? You can choose any order of the letters of the given string but you can't add any new letters or remove the existing ones. You can also leave the order the same.
If there are multiple answers, print any of them.
You also have to answer $T$ separate queries.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 100$) β the number of queries.
Each of the next $T$ lines contains string $s$ $(1 \le |s| \le 100)$ β the string for the next query. It is guaranteed that it contains only lowercase Latin letters.
Note that in hacks you have to set $T = 1$.
-----Output-----
Print $T$ lines. The $i$-th line should contain the answer to the $i$-th query.
If the answer for the $i$-th query exists, then print such a rearrangment of letters of the given string that it contains no ugly pairs. You can choose any order of the letters of the given string but you can't add any new letters or remove the existing ones. You can also leave the order the same.
If there are multiple answers, print any of them.
Otherwise print "No answer" for that query.
-----Example-----
Input
4
abcd
gg
codeforces
abaca
Output
cadb
gg
codfoerces
No answer
-----Note-----
In the first example answer "bdac" is also correct.
The second example showcases the fact that only neighbouring in alphabet letters are not allowed. The same letter is ok.
There are lots of valid answers for the third example.
|
from sys import stdin
input = stdin.readline
t = int(input())
for _ in range(t):
s = list(input().rstrip())
even = []
odd = []
for c in s:
if ord(c) % 2 == 0:
even.append(c)
else:
odd.append(c)
even.sort()
odd.sort()
if even == [] or odd == []:
print(*s, sep="")
continue
if abs(ord(even[0]) - ord(odd[-1])) != 1:
ans = odd + even
print(*ans, sep="")
continue
if abs(ord(even[-1]) - ord(odd[0])) != 1:
ans = even + odd
print(*ans, sep="")
continue
print("No answer")
|
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR IF VAR LIST VAR LIST EXPR FUNC_CALL VAR VAR STRING IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR STRING IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR STRING
|
You are given a string, consisting of lowercase Latin letters.
A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β "ab" and $(2, 3)$ β "ba". Letters 'a' and 'z' aren't considered neighbouring in a alphabet.
Can you rearrange the letters of a given string so that there are no ugly pairs? You can choose any order of the letters of the given string but you can't add any new letters or remove the existing ones. You can also leave the order the same.
If there are multiple answers, print any of them.
You also have to answer $T$ separate queries.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 100$) β the number of queries.
Each of the next $T$ lines contains string $s$ $(1 \le |s| \le 100)$ β the string for the next query. It is guaranteed that it contains only lowercase Latin letters.
Note that in hacks you have to set $T = 1$.
-----Output-----
Print $T$ lines. The $i$-th line should contain the answer to the $i$-th query.
If the answer for the $i$-th query exists, then print such a rearrangment of letters of the given string that it contains no ugly pairs. You can choose any order of the letters of the given string but you can't add any new letters or remove the existing ones. You can also leave the order the same.
If there are multiple answers, print any of them.
Otherwise print "No answer" for that query.
-----Example-----
Input
4
abcd
gg
codeforces
abaca
Output
cadb
gg
codfoerces
No answer
-----Note-----
In the first example answer "bdac" is also correct.
The second example showcases the fact that only neighbouring in alphabet letters are not allowed. The same letter is ok.
There are lots of valid answers for the third example.
|
a = int(input())
for i in range(a):
A = []
b = input()
for j in range(len(b)):
A.append(ord(b[j]) - 96)
A.sort()
B = []
C = []
q = 1
B.append(A[0])
for j in range(1, len(b)):
if A[j] != A[j - 1]:
q *= -1
if q == 1:
B.append(A[j])
else:
C.append(A[j])
S = C + B
w = ""
k = True
w += chr(S[0] + 96)
for j in range(1, len(S)):
if k == True:
if abs(S[j] - S[j - 1]) != 1:
w += chr(S[j] + 96)
else:
k = False
V = B + C
e = chr(V[0] + 96)
l = True
for j in range(1, len(V)):
if l == True:
if abs(V[j] - V[j - 1]) != 1:
e += chr(V[j] + 96)
else:
l = False
if k == True:
print(w)
elif l == True:
print(e)
else:
print("No answer")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
|
You are given a string, consisting of lowercase Latin letters.
A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β "ab" and $(2, 3)$ β "ba". Letters 'a' and 'z' aren't considered neighbouring in a alphabet.
Can you rearrange the letters of a given string so that there are no ugly pairs? You can choose any order of the letters of the given string but you can't add any new letters or remove the existing ones. You can also leave the order the same.
If there are multiple answers, print any of them.
You also have to answer $T$ separate queries.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 100$) β the number of queries.
Each of the next $T$ lines contains string $s$ $(1 \le |s| \le 100)$ β the string for the next query. It is guaranteed that it contains only lowercase Latin letters.
Note that in hacks you have to set $T = 1$.
-----Output-----
Print $T$ lines. The $i$-th line should contain the answer to the $i$-th query.
If the answer for the $i$-th query exists, then print such a rearrangment of letters of the given string that it contains no ugly pairs. You can choose any order of the letters of the given string but you can't add any new letters or remove the existing ones. You can also leave the order the same.
If there are multiple answers, print any of them.
Otherwise print "No answer" for that query.
-----Example-----
Input
4
abcd
gg
codeforces
abaca
Output
cadb
gg
codfoerces
No answer
-----Note-----
In the first example answer "bdac" is also correct.
The second example showcases the fact that only neighbouring in alphabet letters are not allowed. The same letter is ok.
There are lots of valid answers for the third example.
|
def check(s):
for i in range(0, len(s) - 1):
if abs(ord(s[i]) - ord(s[i + 1])) == 1:
return False
return True
t = int(input())
m = "acegikmoqsuwybdfhjlnprtvxz"
n = "bdfhjlnprtvxzacegikmoqsuwy"
while t > 0:
s = input()
cnt = dict()
ans = ""
for i in s:
cnt[i] = s.count(i)
for i in m:
if cnt.__contains__(i):
for j in range(0, cnt[i]):
ans = ans + i
if check(ans):
print(ans)
else:
ans = ""
for i in n:
if cnt.__contains__(i):
for j in range(0, cnt[i]):
ans = ans + i
if check(ans):
print(ans)
else:
print("No answer")
t = t - 1
|
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR STRING FOR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FOR VAR VAR IF FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING FOR VAR VAR IF FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR NUMBER
|
You are given a string, consisting of lowercase Latin letters.
A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β "ab" and $(2, 3)$ β "ba". Letters 'a' and 'z' aren't considered neighbouring in a alphabet.
Can you rearrange the letters of a given string so that there are no ugly pairs? You can choose any order of the letters of the given string but you can't add any new letters or remove the existing ones. You can also leave the order the same.
If there are multiple answers, print any of them.
You also have to answer $T$ separate queries.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 100$) β the number of queries.
Each of the next $T$ lines contains string $s$ $(1 \le |s| \le 100)$ β the string for the next query. It is guaranteed that it contains only lowercase Latin letters.
Note that in hacks you have to set $T = 1$.
-----Output-----
Print $T$ lines. The $i$-th line should contain the answer to the $i$-th query.
If the answer for the $i$-th query exists, then print such a rearrangment of letters of the given string that it contains no ugly pairs. You can choose any order of the letters of the given string but you can't add any new letters or remove the existing ones. You can also leave the order the same.
If there are multiple answers, print any of them.
Otherwise print "No answer" for that query.
-----Example-----
Input
4
abcd
gg
codeforces
abaca
Output
cadb
gg
codfoerces
No answer
-----Note-----
In the first example answer "bdac" is also correct.
The second example showcases the fact that only neighbouring in alphabet letters are not allowed. The same letter is ok.
There are lots of valid answers for the third example.
|
n = int(input())
def ind_max(array, i):
flg = 0
if i == None:
m = max(array)
k = 0
while k < 26:
if (array[k] == m) & (digits[k] > 0):
flg = 1
break
else:
k += 1
else:
m = array[i]
for j in range(len(array)):
if abs(i - j) != 1:
if array[j] > m:
m = array[j]
k = 0
while k < 26:
if (array[k] == m) & (abs(k - i) != 1) & (digits[k] > 0):
flg = 1
break
else:
k += 1
if flg == 0:
return -1
else:
return k
def in_order(digits, friends):
result = []
ind = None
for i in range(sum(digits)):
ind = ind_max(friends, ind)
if ind == -1:
return print("No answer")
result.append(chr(ind + 97))
digits[ind] -= 1
if ind > 0:
friends[ind - 1] -= 1
if ind < 25:
friends[ind + 1] -= 1
if digits[ind] == 0:
friends[ind] = 0
return print("".join(result))
ss = []
for i in range(n):
s = input()
ss.append(s)
for s in ss:
digits = [(0) for i in range(26)]
friends = [(0) for i in range(26)]
for ch in s:
k = ord(ch) - 97
digits[k] += 1
if k > 0:
friends[k - 1] += 1
if k < 25:
friends[k + 1] += 1
for j in range(26):
if digits[j] == 0:
friends[j] = 0
in_order(digits, friends)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER IF VAR NONE ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER RETURN NUMBER RETURN VAR FUNC_DEF ASSIGN VAR LIST ASSIGN VAR NONE FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NUMBER RETURN FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER RETURN FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR
|
You are given a string, consisting of lowercase Latin letters.
A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β "ab" and $(2, 3)$ β "ba". Letters 'a' and 'z' aren't considered neighbouring in a alphabet.
Can you rearrange the letters of a given string so that there are no ugly pairs? You can choose any order of the letters of the given string but you can't add any new letters or remove the existing ones. You can also leave the order the same.
If there are multiple answers, print any of them.
You also have to answer $T$ separate queries.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 100$) β the number of queries.
Each of the next $T$ lines contains string $s$ $(1 \le |s| \le 100)$ β the string for the next query. It is guaranteed that it contains only lowercase Latin letters.
Note that in hacks you have to set $T = 1$.
-----Output-----
Print $T$ lines. The $i$-th line should contain the answer to the $i$-th query.
If the answer for the $i$-th query exists, then print such a rearrangment of letters of the given string that it contains no ugly pairs. You can choose any order of the letters of the given string but you can't add any new letters or remove the existing ones. You can also leave the order the same.
If there are multiple answers, print any of them.
Otherwise print "No answer" for that query.
-----Example-----
Input
4
abcd
gg
codeforces
abaca
Output
cadb
gg
codfoerces
No answer
-----Note-----
In the first example answer "bdac" is also correct.
The second example showcases the fact that only neighbouring in alphabet letters are not allowed. The same letter is ok.
There are lots of valid answers for the third example.
|
q = int(input())
b = []
c = []
for p in range(q):
b = []
c = []
e = []
a = list(input())
for i in range(len(a)):
if a[i] == "a":
a[i] = 1
if a[i] == "b":
a[i] = 2
if a[i] == "c":
a[i] = 3
if a[i] == "d":
a[i] = 4
if a[i] == "e":
a[i] = 5
if a[i] == "f":
a[i] = 6
if a[i] == "g":
a[i] = 7
if a[i] == "h":
a[i] = 8
if a[i] == "i":
a[i] = 9
if a[i] == "j":
a[i] = 10
if a[i] == "k":
a[i] = 11
if a[i] == "l":
a[i] = 12
if a[i] == "m":
a[i] = 13
if a[i] == "n":
a[i] = 14
if a[i] == "o":
a[i] = 15
if a[i] == "p":
a[i] = 16
if a[i] == "q":
a[i] = 17
if a[i] == "r":
a[i] = 18
if a[i] == "s":
a[i] = 19
if a[i] == "t":
a[i] = 20
if a[i] == "u":
a[i] = 21
if a[i] == "v":
a[i] = 22
if a[i] == "w":
a[i] = 23
if a[i] == "x":
a[i] = 24
if a[i] == "y":
a[i] = 25
if a[i] == "z":
a[i] = 26
d = sorted(a)
for j in range(len(d)):
if d[j] % 2 == 0:
c.append(d[j])
else:
b.append(d[j])
if not b:
e = c[:]
elif not c:
e = b[:]
elif abs(c[-1] - b[0]) != 1:
e = c[:] + b[:]
elif abs(b[-1] - c[0]) != 1:
e = b[:] + c[:]
else:
print("No answer")
continue
for i in range(len(e)):
if e[i] == 1:
e[i] = "a"
if e[i] == 2:
e[i] = "b"
if e[i] == 3:
e[i] = "c"
if e[i] == 4:
e[i] = "d"
if e[i] == 5:
e[i] = "e"
if e[i] == 6:
e[i] = "f"
if e[i] == 7:
e[i] = "g"
if e[i] == 8:
e[i] = "h"
if e[i] == 9:
e[i] = "i"
if e[i] == 10:
e[i] = "j"
if e[i] == 11:
e[i] = "k"
if e[i] == 12:
e[i] = "l"
if e[i] == 13:
e[i] = "m"
if e[i] == 14:
e[i] = "n"
if e[i] == 15:
e[i] = "o"
if e[i] == 16:
e[i] = "p"
if e[i] == 17:
e[i] = "q"
if e[i] == 18:
e[i] = "r"
if e[i] == 19:
e[i] = "s"
if e[i] == 20:
e[i] = "t"
if e[i] == 21:
e[i] = "u"
if e[i] == 22:
e[i] = "v"
if e[i] == 23:
e[i] = "w"
if e[i] == 24:
e[i] = "x"
if e[i] == 25:
e[i] = "y"
if e[i] == 26:
e[i] = "z"
if len(e) > 0:
print(*e, sep="")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR NUMBER IF VAR VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR IF VAR ASSIGN VAR VAR IF VAR ASSIGN VAR VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR STRING IF VAR VAR NUMBER ASSIGN VAR VAR STRING IF VAR VAR NUMBER ASSIGN VAR VAR STRING IF VAR VAR NUMBER ASSIGN VAR VAR STRING IF VAR VAR NUMBER ASSIGN VAR VAR STRING IF VAR VAR NUMBER ASSIGN VAR VAR STRING IF VAR VAR NUMBER ASSIGN VAR VAR STRING IF VAR VAR NUMBER ASSIGN VAR VAR STRING IF VAR VAR NUMBER ASSIGN VAR VAR STRING IF VAR VAR NUMBER ASSIGN VAR VAR STRING IF VAR VAR NUMBER ASSIGN VAR VAR STRING IF VAR VAR NUMBER ASSIGN VAR VAR STRING IF VAR VAR NUMBER ASSIGN VAR VAR STRING IF VAR VAR NUMBER ASSIGN VAR VAR STRING IF VAR VAR NUMBER ASSIGN VAR VAR STRING IF VAR VAR NUMBER ASSIGN VAR VAR STRING IF VAR VAR NUMBER ASSIGN VAR VAR STRING IF VAR VAR NUMBER ASSIGN VAR VAR STRING IF VAR VAR NUMBER ASSIGN VAR VAR STRING IF VAR VAR NUMBER ASSIGN VAR VAR STRING IF VAR VAR NUMBER ASSIGN VAR VAR STRING IF VAR VAR NUMBER ASSIGN VAR VAR STRING IF VAR VAR NUMBER ASSIGN VAR VAR STRING IF VAR VAR NUMBER ASSIGN VAR VAR STRING IF VAR VAR NUMBER ASSIGN VAR VAR STRING IF VAR VAR NUMBER ASSIGN VAR VAR STRING IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR STRING
|
You are given a string, consisting of lowercase Latin letters.
A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β "ab" and $(2, 3)$ β "ba". Letters 'a' and 'z' aren't considered neighbouring in a alphabet.
Can you rearrange the letters of a given string so that there are no ugly pairs? You can choose any order of the letters of the given string but you can't add any new letters or remove the existing ones. You can also leave the order the same.
If there are multiple answers, print any of them.
You also have to answer $T$ separate queries.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 100$) β the number of queries.
Each of the next $T$ lines contains string $s$ $(1 \le |s| \le 100)$ β the string for the next query. It is guaranteed that it contains only lowercase Latin letters.
Note that in hacks you have to set $T = 1$.
-----Output-----
Print $T$ lines. The $i$-th line should contain the answer to the $i$-th query.
If the answer for the $i$-th query exists, then print such a rearrangment of letters of the given string that it contains no ugly pairs. You can choose any order of the letters of the given string but you can't add any new letters or remove the existing ones. You can also leave the order the same.
If there are multiple answers, print any of them.
Otherwise print "No answer" for that query.
-----Example-----
Input
4
abcd
gg
codeforces
abaca
Output
cadb
gg
codfoerces
No answer
-----Note-----
In the first example answer "bdac" is also correct.
The second example showcases the fact that only neighbouring in alphabet letters are not allowed. The same letter is ok.
There are lots of valid answers for the third example.
|
def is_all_zero(l):
for i in l:
if i != 0:
return False
return True
def main():
n = int(input())
for _ in range(n):
l = [0] * 26
s = input()
for i in s:
l[ord(i) - ord("a")] += 1
pr = []
l1 = l[::2]
l2 = l[1::2]
if is_all_zero(l1):
for i in range(13):
for j in range(l2[i]):
pr.append(chr(ord("a") + 2 * i + 1))
print("".join(pr))
continue
if is_all_zero(l2):
for i in range(13):
for j in range(l1[i]):
pr.append(chr(ord("a") + 2 * i))
print("".join(pr))
continue
res = -1, -1
for i in range(13):
for j in range(13):
if not (i - j in (0, 1) or l[2 * i] * l[2 * j + 1] == 0):
res = i, j
if res == (-1, -1):
print("No answer")
else:
for i in range(13):
if i != res[0]:
for j in range(l1[i]):
pr.append(chr(ord("a") + 2 * i))
for j in range(l1[res[0]]):
pr.append(chr(ord("a") + 2 * res[0]))
for j in range(l2[res[1]]):
pr.append(chr(ord("a") + 2 * res[1] + 1))
for i in range(13):
if i != res[1]:
for j in range(l2[i]):
pr.append(chr(ord("a") + 2 * i + 1))
print("".join(pr))
return
main()
|
FUNC_DEF FOR VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR LIST ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR STRING BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR IF FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR NUMBER NUMBER BIN_OP VAR BIN_OP NUMBER VAR VAR BIN_OP BIN_OP NUMBER VAR NUMBER NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR STRING BIN_OP NUMBER VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR STRING BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR RETURN EXPR FUNC_CALL VAR
|
You are given a string, consisting of lowercase Latin letters.
A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β "ab" and $(2, 3)$ β "ba". Letters 'a' and 'z' aren't considered neighbouring in a alphabet.
Can you rearrange the letters of a given string so that there are no ugly pairs? You can choose any order of the letters of the given string but you can't add any new letters or remove the existing ones. You can also leave the order the same.
If there are multiple answers, print any of them.
You also have to answer $T$ separate queries.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 100$) β the number of queries.
Each of the next $T$ lines contains string $s$ $(1 \le |s| \le 100)$ β the string for the next query. It is guaranteed that it contains only lowercase Latin letters.
Note that in hacks you have to set $T = 1$.
-----Output-----
Print $T$ lines. The $i$-th line should contain the answer to the $i$-th query.
If the answer for the $i$-th query exists, then print such a rearrangment of letters of the given string that it contains no ugly pairs. You can choose any order of the letters of the given string but you can't add any new letters or remove the existing ones. You can also leave the order the same.
If there are multiple answers, print any of them.
Otherwise print "No answer" for that query.
-----Example-----
Input
4
abcd
gg
codeforces
abaca
Output
cadb
gg
codfoerces
No answer
-----Note-----
In the first example answer "bdac" is also correct.
The second example showcases the fact that only neighbouring in alphabet letters are not allowed. The same letter is ok.
There are lots of valid answers for the third example.
|
T = int(input())
for _ in range(T):
s = input()
d = {}
for i in s:
d[i] = d.get(i, 0) + 1
k = sorted(list(d.keys()))
n = len(k)
if n == 2:
if abs(ord(k[0]) - ord(k[1])) == 1:
ans = "No answer"
else:
ans = s
elif n == 3:
if abs(ord(k[0]) - ord(k[2])) == 2:
ans = "No answer"
elif abs(ord(k[0]) - ord(k[1])) == 1:
ans = k[0] * d[k[0]] + k[2] * d[k[2]] + k[1] * d[k[1]]
else:
ans = k[2] * d[k[2]] + k[0] * d[k[0]] + k[1] * d[k[1]]
else:
ans = ""
for i in range(n // 2):
j = n // 2 + i
ans += k[j] * d[k[j]] + k[i] * d[k[i]]
if n % 2 == 1:
ans += k[n - 1] * d[k[n - 1]]
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR NUMBER IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR STRING ASSIGN VAR VAR IF VAR NUMBER IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR STRING IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP VAR NUMBER VAR VAR NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given a string, consisting of lowercase Latin letters.
A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β "ab" and $(2, 3)$ β "ba". Letters 'a' and 'z' aren't considered neighbouring in a alphabet.
Can you rearrange the letters of a given string so that there are no ugly pairs? You can choose any order of the letters of the given string but you can't add any new letters or remove the existing ones. You can also leave the order the same.
If there are multiple answers, print any of them.
You also have to answer $T$ separate queries.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 100$) β the number of queries.
Each of the next $T$ lines contains string $s$ $(1 \le |s| \le 100)$ β the string for the next query. It is guaranteed that it contains only lowercase Latin letters.
Note that in hacks you have to set $T = 1$.
-----Output-----
Print $T$ lines. The $i$-th line should contain the answer to the $i$-th query.
If the answer for the $i$-th query exists, then print such a rearrangment of letters of the given string that it contains no ugly pairs. You can choose any order of the letters of the given string but you can't add any new letters or remove the existing ones. You can also leave the order the same.
If there are multiple answers, print any of them.
Otherwise print "No answer" for that query.
-----Example-----
Input
4
abcd
gg
codeforces
abaca
Output
cadb
gg
codfoerces
No answer
-----Note-----
In the first example answer "bdac" is also correct.
The second example showcases the fact that only neighbouring in alphabet letters are not allowed. The same letter is ok.
There are lots of valid answers for the third example.
|
def check(s):
for i in range(len(s) - 1):
if abs(ord(s[i]) - ord(s[i + 1])) == 1:
return False
return True
query = int(input())
while query > 0:
raw = input()
sorted_str = "".join(sorted(raw))
new1 = ""
l = 0
r = len(sorted_str) - 1
while l <= r:
i = l
while i < len(sorted_str) and sorted_str[i] == sorted_str[l]:
new1 += sorted_str[i]
i += 1
l = i
if l > r:
break
j = r
while j > 0 and sorted_str[j] == sorted_str[r]:
new1 += sorted_str[j]
j -= 1
r = j
if check(new1):
print(new1)
else:
new2 = ""
j = len(new1) - 1
while j >= 1 and new1[j] == new1[-1]:
j -= 1
if j == 0:
new2 = new1
else:
new2 = new1[j + 1 :] + new1[: j + 1]
if check(new2):
print(new2)
else:
print("No answer")
query -= 1
|
FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR WHILE VAR NUMBER VAR VAR VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR NUMBER VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING VAR NUMBER
|
You are given a string, consisting of lowercase Latin letters.
A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β "ab" and $(2, 3)$ β "ba". Letters 'a' and 'z' aren't considered neighbouring in a alphabet.
Can you rearrange the letters of a given string so that there are no ugly pairs? You can choose any order of the letters of the given string but you can't add any new letters or remove the existing ones. You can also leave the order the same.
If there are multiple answers, print any of them.
You also have to answer $T$ separate queries.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 100$) β the number of queries.
Each of the next $T$ lines contains string $s$ $(1 \le |s| \le 100)$ β the string for the next query. It is guaranteed that it contains only lowercase Latin letters.
Note that in hacks you have to set $T = 1$.
-----Output-----
Print $T$ lines. The $i$-th line should contain the answer to the $i$-th query.
If the answer for the $i$-th query exists, then print such a rearrangment of letters of the given string that it contains no ugly pairs. You can choose any order of the letters of the given string but you can't add any new letters or remove the existing ones. You can also leave the order the same.
If there are multiple answers, print any of them.
Otherwise print "No answer" for that query.
-----Example-----
Input
4
abcd
gg
codeforces
abaca
Output
cadb
gg
codfoerces
No answer
-----Note-----
In the first example answer "bdac" is also correct.
The second example showcases the fact that only neighbouring in alphabet letters are not allowed. The same letter is ok.
There are lots of valid answers for the third example.
|
nums = int(input())
strings = [input() for _ in range(nums)]
for i in strings:
odds = []
evens = []
for j in i:
if ord(j) - 97 & 1 == 0:
evens.append(j)
else:
odds.append(j)
num = None
possible = False
if len(odds) == 0 or len(evens) == 0:
possible = True
print(i)
else:
high_odd = odds.index(max(odds))
low_odd = odds.index(min(odds))
high_even = evens.index(max(evens))
low_even = evens.index(min(evens))
if abs(ord(odds[low_odd]) - ord(evens[high_even])) != 1:
odd_letter = odds.pop(low_odd)
even_letter = evens.pop(high_even)
possible = True
print("".join(odds) + odd_letter + even_letter + "".join(evens))
elif abs(ord(odds[high_odd]) - ord(evens[low_even])) != 1:
odd_letter = odds.pop(high_odd)
even_letter = evens.pop(low_even)
possible = True
print("".join(odds) + odd_letter + even_letter + "".join(evens))
if not possible:
print("No answer")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FOR VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR IF BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NONE ASSIGN VAR NUMBER IF FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL STRING VAR VAR VAR FUNC_CALL STRING VAR IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP FUNC_CALL STRING VAR VAR VAR FUNC_CALL STRING VAR IF VAR EXPR FUNC_CALL VAR STRING
|
You are given a string, consisting of lowercase Latin letters.
A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β "ab" and $(2, 3)$ β "ba". Letters 'a' and 'z' aren't considered neighbouring in a alphabet.
Can you rearrange the letters of a given string so that there are no ugly pairs? You can choose any order of the letters of the given string but you can't add any new letters or remove the existing ones. You can also leave the order the same.
If there are multiple answers, print any of them.
You also have to answer $T$ separate queries.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 100$) β the number of queries.
Each of the next $T$ lines contains string $s$ $(1 \le |s| \le 100)$ β the string for the next query. It is guaranteed that it contains only lowercase Latin letters.
Note that in hacks you have to set $T = 1$.
-----Output-----
Print $T$ lines. The $i$-th line should contain the answer to the $i$-th query.
If the answer for the $i$-th query exists, then print such a rearrangment of letters of the given string that it contains no ugly pairs. You can choose any order of the letters of the given string but you can't add any new letters or remove the existing ones. You can also leave the order the same.
If there are multiple answers, print any of them.
Otherwise print "No answer" for that query.
-----Example-----
Input
4
abcd
gg
codeforces
abaca
Output
cadb
gg
codfoerces
No answer
-----Note-----
In the first example answer "bdac" is also correct.
The second example showcases the fact that only neighbouring in alphabet letters are not allowed. The same letter is ok.
There are lots of valid answers for the third example.
|
t = int(input())
for _ in range(t):
s = str(input())
def check(s):
n = len(s)
for i in range(n - 1):
if abs(ord(s[i]) - ord(s[i + 1])) == 1:
return False
else:
return True
odd = []
even = []
for c in s:
i = ord(c) - ord("a")
if i % 2 == 0:
even.append(c)
else:
odd.append(c)
odd.sort()
even.sort()
s1 = "".join(odd + even)
s2 = "".join(even + odd)
if check(s1):
print(s1)
elif check(s2):
print(s2)
else:
print("No answer")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL STRING BIN_OP VAR VAR ASSIGN VAR FUNC_CALL STRING BIN_OP VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
|
You are given a string, consisting of lowercase Latin letters.
A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β "ab" and $(2, 3)$ β "ba". Letters 'a' and 'z' aren't considered neighbouring in a alphabet.
Can you rearrange the letters of a given string so that there are no ugly pairs? You can choose any order of the letters of the given string but you can't add any new letters or remove the existing ones. You can also leave the order the same.
If there are multiple answers, print any of them.
You also have to answer $T$ separate queries.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 100$) β the number of queries.
Each of the next $T$ lines contains string $s$ $(1 \le |s| \le 100)$ β the string for the next query. It is guaranteed that it contains only lowercase Latin letters.
Note that in hacks you have to set $T = 1$.
-----Output-----
Print $T$ lines. The $i$-th line should contain the answer to the $i$-th query.
If the answer for the $i$-th query exists, then print such a rearrangment of letters of the given string that it contains no ugly pairs. You can choose any order of the letters of the given string but you can't add any new letters or remove the existing ones. You can also leave the order the same.
If there are multiple answers, print any of them.
Otherwise print "No answer" for that query.
-----Example-----
Input
4
abcd
gg
codeforces
abaca
Output
cadb
gg
codfoerces
No answer
-----Note-----
In the first example answer "bdac" is also correct.
The second example showcases the fact that only neighbouring in alphabet letters are not allowed. The same letter is ok.
There are lots of valid answers for the third example.
|
import sys
T = int(sys.stdin.readline().strip())
for t in range(0, T):
s = sys.stdin.readline().strip()
x = [0] * 26
y = ord("a")
for l in s:
i = ord(l) - y
x[i] = x[i] + 1
n = 0
s1 = ""
s2 = ""
for i in range(0, 26):
if x[i] != 0:
if n % 2 == 0:
s1 = s1 + x[i] * chr(i + y)
else:
s2 = s2 + x[i] * chr(i + y)
n = n + 1
if n == 1:
print(s)
elif (ord(s1[0]) - ord(s2[-1])) ** 2 != 1:
print(s2 + s1)
elif (ord(s2[0]) - ord(s1[-1])) ** 2 != 1:
print(s1 + s2)
else:
print("No answer")
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR IF BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING
|
You are given a string, consisting of lowercase Latin letters.
A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β "ab" and $(2, 3)$ β "ba". Letters 'a' and 'z' aren't considered neighbouring in a alphabet.
Can you rearrange the letters of a given string so that there are no ugly pairs? You can choose any order of the letters of the given string but you can't add any new letters or remove the existing ones. You can also leave the order the same.
If there are multiple answers, print any of them.
You also have to answer $T$ separate queries.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 100$) β the number of queries.
Each of the next $T$ lines contains string $s$ $(1 \le |s| \le 100)$ β the string for the next query. It is guaranteed that it contains only lowercase Latin letters.
Note that in hacks you have to set $T = 1$.
-----Output-----
Print $T$ lines. The $i$-th line should contain the answer to the $i$-th query.
If the answer for the $i$-th query exists, then print such a rearrangment of letters of the given string that it contains no ugly pairs. You can choose any order of the letters of the given string but you can't add any new letters or remove the existing ones. You can also leave the order the same.
If there are multiple answers, print any of them.
Otherwise print "No answer" for that query.
-----Example-----
Input
4
abcd
gg
codeforces
abaca
Output
cadb
gg
codfoerces
No answer
-----Note-----
In the first example answer "bdac" is also correct.
The second example showcases the fact that only neighbouring in alphabet letters are not allowed. The same letter is ok.
There are lots of valid answers for the third example.
|
t = int(input())
al = [
"a",
"b",
"c",
"d",
"e",
"f",
"g",
"h",
"i",
"j",
"k",
"l",
"m",
"n",
"o",
"p",
"q",
"r",
"s",
"t",
"u",
"v",
"w",
"x",
"y",
"z",
]
hash = {}
for i in range(26):
hash[al[i]] = i
for i in range(t):
s = list(input())
s.sort()
ans = ""
ans1 = ""
for i in range(len(s)):
if hash[s[i]] % 2 == 0:
ans += s[i]
else:
ans1 += s[i]
c1 = "".join(sorted(list(ans)))
c2 = "".join(sorted(list(ans1)))
k = c1 + c2
k1 = c2 + c1
flag = 0
flag1 = 0
for i in range(len(s) - 1):
if abs(hash[k[i]] - hash[k[i + 1]]) == 1:
flag = 1
if abs(hash[k1[i]] - hash[k1[i + 1]]) == 1:
flag1 = 1
if flag == 0:
print(k)
elif flag1 == 0:
print(k1)
else:
print("No answer")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING ASSIGN VAR DICT FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR STRING ASSIGN VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER NUMBER VAR VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
|
You are given a string, consisting of lowercase Latin letters.
A pair of neighbouring letters in a string is considered ugly if these letters are also neighbouring in a alphabet. For example, string "abaca" contains ugly pairs at positions $(1, 2)$ β "ab" and $(2, 3)$ β "ba". Letters 'a' and 'z' aren't considered neighbouring in a alphabet.
Can you rearrange the letters of a given string so that there are no ugly pairs? You can choose any order of the letters of the given string but you can't add any new letters or remove the existing ones. You can also leave the order the same.
If there are multiple answers, print any of them.
You also have to answer $T$ separate queries.
-----Input-----
The first line contains a single integer $T$ ($1 \le T \le 100$) β the number of queries.
Each of the next $T$ lines contains string $s$ $(1 \le |s| \le 100)$ β the string for the next query. It is guaranteed that it contains only lowercase Latin letters.
Note that in hacks you have to set $T = 1$.
-----Output-----
Print $T$ lines. The $i$-th line should contain the answer to the $i$-th query.
If the answer for the $i$-th query exists, then print such a rearrangment of letters of the given string that it contains no ugly pairs. You can choose any order of the letters of the given string but you can't add any new letters or remove the existing ones. You can also leave the order the same.
If there are multiple answers, print any of them.
Otherwise print "No answer" for that query.
-----Example-----
Input
4
abcd
gg
codeforces
abaca
Output
cadb
gg
codfoerces
No answer
-----Note-----
In the first example answer "bdac" is also correct.
The second example showcases the fact that only neighbouring in alphabet letters are not allowed. The same letter is ok.
There are lots of valid answers for the third example.
|
n = int(input())
for _ in range(n):
s = input()
a = [ord(x) for x in s]
a.sort()
letter = [a[0]]
count = [0]
for c in a:
if c == letter[-1]:
count[-1] = count[-1] + 1
else:
letter.append(c)
count.append(1)
if len(letter) == 1:
print(s)
continue
if len(letter) == 2:
if letter[0] + 1 < letter[1]:
print(s)
else:
print("No answer")
continue
if len(letter) == 3:
if letter[0] + 1 == letter[1] and letter[1] + 1 == letter[2]:
print("No answer")
continue
ans = chr(letter[0]) * count[0]
if letter[0] + 1 == letter[1]:
letter.append(letter[1])
count.append(count[1])
else:
ans = ans + chr(letter[1]) * count[1]
for y in range(2, len(letter)):
if letter[y] == ord(ans[-1]) + 1 or letter[y] == ord(ans[-1]) - 1:
ans = chr(letter[y]) * count[y] + ans
else:
ans = ans + chr(letter[y]) * count[y]
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP FUNC_CALL VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
After the educational reform Polycarp studies only two subjects at school, Safety Studies and PE (Physical Education). During the long months of the fourth term, he received n marks in them. When teachers wrote a mark in the journal, they didn't write in what subject the mark was for, they just wrote the mark.
Now it's time to show the journal to his strict parents. Polycarp knows that recently at the Parent Meeting the parents were told that he received a Safety Studies marks and b PE marks (a + b = n). Now Polycarp wants to write a subject's name in front of each mark so that:
* there are exactly a Safety Studies marks,
* there are exactly b PE marks,
* the total average score in both subjects is maximum.
An average subject grade is the sum of all marks in it, divided by the number of them. Of course, the division is performed in real numbers without rounding up or down. Polycarp aims to maximize the x1 + x2, where x1 is the average score in the first subject (Safety Studies), and x2 is the average score in the second one (Physical Education).
Input
The first line contains an integer n (2 β€ n β€ 105), n is the number of marks in Polycarp's Journal. The second line contains two positive integers a, b (1 β€ a, b β€ n - 1, a + b = n). The third line contains a sequence of integers t1, t2, ..., tn (1 β€ ti β€ 5), they are Polycarp's marks.
Output
Print the sequence of integers f1, f2, ..., fn, where fi (1 β€ fi β€ 2) is the number of a subject to which the i-th mark should be attributed. If there are several possible solutions, then print such that the sequence f1, f2, ..., fn is the smallest lexicographically.
The sequence p1, p2, ..., pn is lexicographically less than q1, q2, ..., qn if there exists such j (1 β€ j β€ n) that pi = qi for all 1 β€ i < j, Π°nd pj < qj.
Examples
Input
5
3 2
4 4 5 4 4
Output
1 1 2 1 2
Input
4
2 2
3 5 4 5
Output
1 1 2 2
Input
6
1 5
4 4 4 5 4 4
Output
2 2 2 1 2 2
Note
In the first sample the average score in the first subject is equal to 4, and in the second one β to 4.5. The total average score is 8.5.
|
n = int(input())
a, b = map(int, input().split())
l = list(map(int, input().split()))
if a == b:
print(*([1] * a + [2] * b))
else:
h = [[l[i], i] for i in range(n)]
h.sort(key=lambda x: x[0])
ans = [(0) for i in range(n)]
if b < a:
i = n - b
j = n - b - 1
if h[i][0] == h[j][0]:
while i < n and h[i][0] == h[n - b][0]:
i += 1
while j > -1 and h[j][0] == h[n - b - 1][0]:
j -= 1
i = i - 1
j = j + 1
na = n - b - j
nb = i - n + b + 1
k = h[j : i + 1]
k.sort(key=lambda x: x[1])
for c in range(na):
k[c][0] = 1
for c in range(na, na + nb):
k[c][0] = 2
for c in range(na + nb):
ans[k[c][1]] = k[c][0]
else:
ans[h[j][1]] = 1
ans[h[i][1]] = 2
for c in range(j):
ans[h[c][1]] = 1
for c in range(i + 1, n):
ans[h[c][1]] = 2
print(*ans)
else:
i = n - a
j = n - a - 1
if h[i][0] == h[j][0]:
while i < n and h[i][0] == h[n - a][0]:
i += 1
while j > -1 and h[j][0] == h[n - a - 1][0]:
j -= 1
i = i - 1
j = j + 1
nb = n - a - j
na = i - n + a + 1
k = h[j : i + 1]
k.sort(key=lambda x: x[1])
for c in range(na):
k[c][0] = 1
for c in range(na, na + nb):
k[c][0] = 2
for c in range(na + nb):
ans[k[c][1]] = k[c][0]
else:
ans[h[j][1]] = 2
ans[h[i][1]] = 1
for c in range(j):
ans[h[c][1]] = 2
for c in range(i + 1, n):
ans[h[c][1]] = 1
print(*ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP LIST NUMBER VAR BIN_OP LIST NUMBER VAR ASSIGN VAR LIST VAR VAR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR NUMBER WHILE VAR NUMBER VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR BIN_OP VAR VAR NUMBER VAR NUMBER WHILE VAR NUMBER VAR VAR NUMBER VAR BIN_OP BIN_OP VAR VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
After the educational reform Polycarp studies only two subjects at school, Safety Studies and PE (Physical Education). During the long months of the fourth term, he received n marks in them. When teachers wrote a mark in the journal, they didn't write in what subject the mark was for, they just wrote the mark.
Now it's time to show the journal to his strict parents. Polycarp knows that recently at the Parent Meeting the parents were told that he received a Safety Studies marks and b PE marks (a + b = n). Now Polycarp wants to write a subject's name in front of each mark so that:
* there are exactly a Safety Studies marks,
* there are exactly b PE marks,
* the total average score in both subjects is maximum.
An average subject grade is the sum of all marks in it, divided by the number of them. Of course, the division is performed in real numbers without rounding up or down. Polycarp aims to maximize the x1 + x2, where x1 is the average score in the first subject (Safety Studies), and x2 is the average score in the second one (Physical Education).
Input
The first line contains an integer n (2 β€ n β€ 105), n is the number of marks in Polycarp's Journal. The second line contains two positive integers a, b (1 β€ a, b β€ n - 1, a + b = n). The third line contains a sequence of integers t1, t2, ..., tn (1 β€ ti β€ 5), they are Polycarp's marks.
Output
Print the sequence of integers f1, f2, ..., fn, where fi (1 β€ fi β€ 2) is the number of a subject to which the i-th mark should be attributed. If there are several possible solutions, then print such that the sequence f1, f2, ..., fn is the smallest lexicographically.
The sequence p1, p2, ..., pn is lexicographically less than q1, q2, ..., qn if there exists such j (1 β€ j β€ n) that pi = qi for all 1 β€ i < j, Π°nd pj < qj.
Examples
Input
5
3 2
4 4 5 4 4
Output
1 1 2 1 2
Input
4
2 2
3 5 4 5
Output
1 1 2 2
Input
6
1 5
4 4 4 5 4 4
Output
2 2 2 1 2 2
Note
In the first sample the average score in the first subject is equal to 4, and in the second one β to 4.5. The total average score is 8.5.
|
n = int(input())
a, b = map(int, input().split())
c = [int(i) for i in input().split()]
p = [i for i in range(n)]
Z = [x for _, x in sorted(zip(c, p))]
ans = [0] * n
if a == b:
for i in range(a):
print(1, end=" ")
for i in range(b):
print(2, end=" ")
exit()
if a > b:
Z = [x for _, x in sorted(zip(c, p))]
for i in range(a):
ans[Z[i]] = 1
for i in range(n):
if ans[i] == 0:
ans[i] = 2
print(*ans)
if a < b:
for i in range(n):
c[i] *= -1
S = [x for _, x in sorted(zip(c, p))]
for i in range(a):
ans[S[i]] = 1
for i in range(n):
if ans[i] == 0:
ans[i] = 2
print(*ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER STRING EXPR FUNC_CALL VAR IF VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR VAR FOR VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
After the educational reform Polycarp studies only two subjects at school, Safety Studies and PE (Physical Education). During the long months of the fourth term, he received n marks in them. When teachers wrote a mark in the journal, they didn't write in what subject the mark was for, they just wrote the mark.
Now it's time to show the journal to his strict parents. Polycarp knows that recently at the Parent Meeting the parents were told that he received a Safety Studies marks and b PE marks (a + b = n). Now Polycarp wants to write a subject's name in front of each mark so that:
* there are exactly a Safety Studies marks,
* there are exactly b PE marks,
* the total average score in both subjects is maximum.
An average subject grade is the sum of all marks in it, divided by the number of them. Of course, the division is performed in real numbers without rounding up or down. Polycarp aims to maximize the x1 + x2, where x1 is the average score in the first subject (Safety Studies), and x2 is the average score in the second one (Physical Education).
Input
The first line contains an integer n (2 β€ n β€ 105), n is the number of marks in Polycarp's Journal. The second line contains two positive integers a, b (1 β€ a, b β€ n - 1, a + b = n). The third line contains a sequence of integers t1, t2, ..., tn (1 β€ ti β€ 5), they are Polycarp's marks.
Output
Print the sequence of integers f1, f2, ..., fn, where fi (1 β€ fi β€ 2) is the number of a subject to which the i-th mark should be attributed. If there are several possible solutions, then print such that the sequence f1, f2, ..., fn is the smallest lexicographically.
The sequence p1, p2, ..., pn is lexicographically less than q1, q2, ..., qn if there exists such j (1 β€ j β€ n) that pi = qi for all 1 β€ i < j, Π°nd pj < qj.
Examples
Input
5
3 2
4 4 5 4 4
Output
1 1 2 1 2
Input
4
2 2
3 5 4 5
Output
1 1 2 2
Input
6
1 5
4 4 4 5 4 4
Output
2 2 2 1 2 2
Note
In the first sample the average score in the first subject is equal to 4, and in the second one β to 4.5. The total average score is 8.5.
|
n = int(input())
a, b = list(map(int, input().split()))
arr = list(map(int, input().split()))
if a == b:
print("1 " * a + "2 " * (a - 1) + "2")
else:
arr = [(j, i) for i, j in enumerate(arr)]
if a < b:
ans = [1] * n
arr.sort(key=lambda x: (x[0], -x[1]))
for i in range(b):
ans[arr[i][1]] = 2
else:
ans = [2] * n
arr.sort(key=lambda x: x[0])
for i in range(a):
ans[arr[i][1]] = 1
print(" ".join(map(str, ans)))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING VAR BIN_OP STRING BIN_OP VAR NUMBER STRING ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR
|
After the educational reform Polycarp studies only two subjects at school, Safety Studies and PE (Physical Education). During the long months of the fourth term, he received n marks in them. When teachers wrote a mark in the journal, they didn't write in what subject the mark was for, they just wrote the mark.
Now it's time to show the journal to his strict parents. Polycarp knows that recently at the Parent Meeting the parents were told that he received a Safety Studies marks and b PE marks (a + b = n). Now Polycarp wants to write a subject's name in front of each mark so that:
* there are exactly a Safety Studies marks,
* there are exactly b PE marks,
* the total average score in both subjects is maximum.
An average subject grade is the sum of all marks in it, divided by the number of them. Of course, the division is performed in real numbers without rounding up or down. Polycarp aims to maximize the x1 + x2, where x1 is the average score in the first subject (Safety Studies), and x2 is the average score in the second one (Physical Education).
Input
The first line contains an integer n (2 β€ n β€ 105), n is the number of marks in Polycarp's Journal. The second line contains two positive integers a, b (1 β€ a, b β€ n - 1, a + b = n). The third line contains a sequence of integers t1, t2, ..., tn (1 β€ ti β€ 5), they are Polycarp's marks.
Output
Print the sequence of integers f1, f2, ..., fn, where fi (1 β€ fi β€ 2) is the number of a subject to which the i-th mark should be attributed. If there are several possible solutions, then print such that the sequence f1, f2, ..., fn is the smallest lexicographically.
The sequence p1, p2, ..., pn is lexicographically less than q1, q2, ..., qn if there exists such j (1 β€ j β€ n) that pi = qi for all 1 β€ i < j, Π°nd pj < qj.
Examples
Input
5
3 2
4 4 5 4 4
Output
1 1 2 1 2
Input
4
2 2
3 5 4 5
Output
1 1 2 2
Input
6
1 5
4 4 4 5 4 4
Output
2 2 2 1 2 2
Note
In the first sample the average score in the first subject is equal to 4, and in the second one β to 4.5. The total average score is 8.5.
|
n = int(input())
a, b = [int(d) for d in input().split()]
t = [int(d) for d in input().split()]
arr = [s for s in range(n)]
if a != b:
arr = sorted(arr, reverse=a < b, key=lambda i: t[i])
for i in arr[0:a]:
t[i] = 1
for i in arr[a:n]:
t[i] = 2
for d in t:
print(d, end=" ")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR FOR VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR STRING
|
After the educational reform Polycarp studies only two subjects at school, Safety Studies and PE (Physical Education). During the long months of the fourth term, he received n marks in them. When teachers wrote a mark in the journal, they didn't write in what subject the mark was for, they just wrote the mark.
Now it's time to show the journal to his strict parents. Polycarp knows that recently at the Parent Meeting the parents were told that he received a Safety Studies marks and b PE marks (a + b = n). Now Polycarp wants to write a subject's name in front of each mark so that:
* there are exactly a Safety Studies marks,
* there are exactly b PE marks,
* the total average score in both subjects is maximum.
An average subject grade is the sum of all marks in it, divided by the number of them. Of course, the division is performed in real numbers without rounding up or down. Polycarp aims to maximize the x1 + x2, where x1 is the average score in the first subject (Safety Studies), and x2 is the average score in the second one (Physical Education).
Input
The first line contains an integer n (2 β€ n β€ 105), n is the number of marks in Polycarp's Journal. The second line contains two positive integers a, b (1 β€ a, b β€ n - 1, a + b = n). The third line contains a sequence of integers t1, t2, ..., tn (1 β€ ti β€ 5), they are Polycarp's marks.
Output
Print the sequence of integers f1, f2, ..., fn, where fi (1 β€ fi β€ 2) is the number of a subject to which the i-th mark should be attributed. If there are several possible solutions, then print such that the sequence f1, f2, ..., fn is the smallest lexicographically.
The sequence p1, p2, ..., pn is lexicographically less than q1, q2, ..., qn if there exists such j (1 β€ j β€ n) that pi = qi for all 1 β€ i < j, Π°nd pj < qj.
Examples
Input
5
3 2
4 4 5 4 4
Output
1 1 2 1 2
Input
4
2 2
3 5 4 5
Output
1 1 2 2
Input
6
1 5
4 4 4 5 4 4
Output
2 2 2 1 2 2
Note
In the first sample the average score in the first subject is equal to 4, and in the second one β to 4.5. The total average score is 8.5.
|
n = int(input())
a, b = list(map(int, input().split()))
c = list(map(int, input().split()))
if a < b:
d = [(1) for i in range(n)]
e = [[] for i in range(5)]
for i in range(n):
e[c[i] - 1].append(i)
e = e[::-1]
for i in range(5):
e1 = len(e[i])
if e1 > a or a == 0:
for j in range(a, e1):
d[e[i][j]] = 2
a = 0
else:
a -= e1
print(*d)
elif a == b:
d = [1] * (n // 2) + [2] * (n // 2)
print(*d)
else:
d = [(2) for i in range(n)]
e = [[] for i in range(5)]
for i in range(n):
e[c[i] - 1].append(i)
e = e[::-1]
for i in range(5):
e1 = len(e[i])
if e1 > b or b == 0:
for j in range(e1 - b):
d[e[i][j]] = 1
b = 0
else:
b -= e1
print(*d)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP LIST NUMBER BIN_OP VAR NUMBER BIN_OP LIST NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR
|
After the educational reform Polycarp studies only two subjects at school, Safety Studies and PE (Physical Education). During the long months of the fourth term, he received n marks in them. When teachers wrote a mark in the journal, they didn't write in what subject the mark was for, they just wrote the mark.
Now it's time to show the journal to his strict parents. Polycarp knows that recently at the Parent Meeting the parents were told that he received a Safety Studies marks and b PE marks (a + b = n). Now Polycarp wants to write a subject's name in front of each mark so that:
* there are exactly a Safety Studies marks,
* there are exactly b PE marks,
* the total average score in both subjects is maximum.
An average subject grade is the sum of all marks in it, divided by the number of them. Of course, the division is performed in real numbers without rounding up or down. Polycarp aims to maximize the x1 + x2, where x1 is the average score in the first subject (Safety Studies), and x2 is the average score in the second one (Physical Education).
Input
The first line contains an integer n (2 β€ n β€ 105), n is the number of marks in Polycarp's Journal. The second line contains two positive integers a, b (1 β€ a, b β€ n - 1, a + b = n). The third line contains a sequence of integers t1, t2, ..., tn (1 β€ ti β€ 5), they are Polycarp's marks.
Output
Print the sequence of integers f1, f2, ..., fn, where fi (1 β€ fi β€ 2) is the number of a subject to which the i-th mark should be attributed. If there are several possible solutions, then print such that the sequence f1, f2, ..., fn is the smallest lexicographically.
The sequence p1, p2, ..., pn is lexicographically less than q1, q2, ..., qn if there exists such j (1 β€ j β€ n) that pi = qi for all 1 β€ i < j, Π°nd pj < qj.
Examples
Input
5
3 2
4 4 5 4 4
Output
1 1 2 1 2
Input
4
2 2
3 5 4 5
Output
1 1 2 2
Input
6
1 5
4 4 4 5 4 4
Output
2 2 2 1 2 2
Note
In the first sample the average score in the first subject is equal to 4, and in the second one β to 4.5. The total average score is 8.5.
|
n = int(input())
a, b = map(int, input().split())
l = list(map(int, input().split()))
arr = [(l[i], i) for i in range(n)]
if a < b:
arr.sort(key=lambda x: (-x[0], x[1]))
else:
arr.sort(key=lambda x: (-x[0], -x[1]))
ans = [0] * n
if a < b:
for i in range(a):
ans[arr[i][1]] = 1
for i in range(a, a + b):
ans[arr[i][1]] = 2
elif a == b:
for i in range(a):
ans[i] = 1
for i in range(a, a + a):
ans[i] = 2
else:
for i in range(b):
ans[arr[i][1]] = 2
for i in range(b, b + a):
ans[arr[i][1]] = 1
print(*ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER IF VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
After the educational reform Polycarp studies only two subjects at school, Safety Studies and PE (Physical Education). During the long months of the fourth term, he received n marks in them. When teachers wrote a mark in the journal, they didn't write in what subject the mark was for, they just wrote the mark.
Now it's time to show the journal to his strict parents. Polycarp knows that recently at the Parent Meeting the parents were told that he received a Safety Studies marks and b PE marks (a + b = n). Now Polycarp wants to write a subject's name in front of each mark so that:
* there are exactly a Safety Studies marks,
* there are exactly b PE marks,
* the total average score in both subjects is maximum.
An average subject grade is the sum of all marks in it, divided by the number of them. Of course, the division is performed in real numbers without rounding up or down. Polycarp aims to maximize the x1 + x2, where x1 is the average score in the first subject (Safety Studies), and x2 is the average score in the second one (Physical Education).
Input
The first line contains an integer n (2 β€ n β€ 105), n is the number of marks in Polycarp's Journal. The second line contains two positive integers a, b (1 β€ a, b β€ n - 1, a + b = n). The third line contains a sequence of integers t1, t2, ..., tn (1 β€ ti β€ 5), they are Polycarp's marks.
Output
Print the sequence of integers f1, f2, ..., fn, where fi (1 β€ fi β€ 2) is the number of a subject to which the i-th mark should be attributed. If there are several possible solutions, then print such that the sequence f1, f2, ..., fn is the smallest lexicographically.
The sequence p1, p2, ..., pn is lexicographically less than q1, q2, ..., qn if there exists such j (1 β€ j β€ n) that pi = qi for all 1 β€ i < j, Π°nd pj < qj.
Examples
Input
5
3 2
4 4 5 4 4
Output
1 1 2 1 2
Input
4
2 2
3 5 4 5
Output
1 1 2 2
Input
6
1 5
4 4 4 5 4 4
Output
2 2 2 1 2 2
Note
In the first sample the average score in the first subject is equal to 4, and in the second one β to 4.5. The total average score is 8.5.
|
import sys
n = int(sys.stdin.readline())
a, b = map(int, sys.stdin.readline().split())
marks = list(map(int, sys.stdin.readline().split()))
if a == b:
sys.stdout.write("1 " * (n // 2) + "2 " * (n // 2 - 1) + "2")
else:
Ans = [2] * n
if a > b:
sorted_marks = sorted(marks)
x = 0
xx = 0
nn = sorted_marks[:a].count(sorted_marks[a - 1])
for i in range(n):
if x < a and marks[i] <= sorted_marks[a - 1]:
if marks[i] == sorted_marks[a - 1] and xx != nn:
x += 1
Ans[i] = 1
xx += 1
elif marks[i] != sorted_marks[a - 1]:
x += 1
Ans[i] = 1
else:
sorted_marks = sorted(marks, reverse=True)
x = 0
xx = 0
nn = sorted_marks[:a].count(sorted_marks[a - 1])
for i in range(n):
if x < a and marks[i] >= sorted_marks[a - 1]:
if marks[i] == sorted_marks[a - 1] and xx != nn:
x += 1
Ans[i] = 1
xx += 1
elif marks[i] != sorted_marks[a - 1]:
x += 1
Ans[i] = 1
for i in range(n - 1):
sys.stdout.write(str(Ans[i]) + " ")
sys.stdout.write(str(Ans[n - 1]))
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP STRING BIN_OP VAR NUMBER BIN_OP STRING BIN_OP BIN_OP VAR NUMBER NUMBER STRING ASSIGN VAR BIN_OP LIST NUMBER VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER
|
After the educational reform Polycarp studies only two subjects at school, Safety Studies and PE (Physical Education). During the long months of the fourth term, he received n marks in them. When teachers wrote a mark in the journal, they didn't write in what subject the mark was for, they just wrote the mark.
Now it's time to show the journal to his strict parents. Polycarp knows that recently at the Parent Meeting the parents were told that he received a Safety Studies marks and b PE marks (a + b = n). Now Polycarp wants to write a subject's name in front of each mark so that:
* there are exactly a Safety Studies marks,
* there are exactly b PE marks,
* the total average score in both subjects is maximum.
An average subject grade is the sum of all marks in it, divided by the number of them. Of course, the division is performed in real numbers without rounding up or down. Polycarp aims to maximize the x1 + x2, where x1 is the average score in the first subject (Safety Studies), and x2 is the average score in the second one (Physical Education).
Input
The first line contains an integer n (2 β€ n β€ 105), n is the number of marks in Polycarp's Journal. The second line contains two positive integers a, b (1 β€ a, b β€ n - 1, a + b = n). The third line contains a sequence of integers t1, t2, ..., tn (1 β€ ti β€ 5), they are Polycarp's marks.
Output
Print the sequence of integers f1, f2, ..., fn, where fi (1 β€ fi β€ 2) is the number of a subject to which the i-th mark should be attributed. If there are several possible solutions, then print such that the sequence f1, f2, ..., fn is the smallest lexicographically.
The sequence p1, p2, ..., pn is lexicographically less than q1, q2, ..., qn if there exists such j (1 β€ j β€ n) that pi = qi for all 1 β€ i < j, Π°nd pj < qj.
Examples
Input
5
3 2
4 4 5 4 4
Output
1 1 2 1 2
Input
4
2 2
3 5 4 5
Output
1 1 2 2
Input
6
1 5
4 4 4 5 4 4
Output
2 2 2 1 2 2
Note
In the first sample the average score in the first subject is equal to 4, and in the second one β to 4.5. The total average score is 8.5.
|
n = int(input())
a, b = map(int, input().split())
if a == b:
print("1 " * a + "2 " * b)
else:
t = [[] for i in range(6)]
for i, j in enumerate(map(int, input().split())):
t[j].append(i)
if b < a:
t = t[1] + t[2] + t[3] + t[4] + t[5]
t.reverse()
p = ["1"] * n
for i in range(b):
p[t[i]] = "2"
print(" ".join(p))
else:
t = t[5] + t[4] + t[3] + t[2] + t[1]
p = ["2"] * n
for i in range(a):
p[t[i]] = "1"
print(" ".join(p))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP STRING VAR BIN_OP STRING VAR ASSIGN VAR LIST VAR FUNC_CALL VAR NUMBER FOR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR STRING EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company.
To settle this problem, they've decided to play a game. The company name will consist of n letters. Oleg and Igor each have a set of n letters (which might contain multiple copies of the same letter, the sets can be different). Initially, the company name is denoted by n question marks. Oleg and Igor takes turns to play the game, Oleg moves first. In each turn, a player can choose one of the letters c in his set and replace any of the question marks with c. Then, a copy of the letter c is removed from his set. The game ends when all the question marks has been replaced by some letter.
For example, suppose Oleg has the set of letters {i, o, i} and Igor has the set of letters {i, m, o}. One possible game is as follows :
Initially, the company name is ???.
Oleg replaces the second question mark with 'i'. The company name becomes ?i?. The set of letters Oleg have now is {i, o}.
Igor replaces the third question mark with 'o'. The company name becomes ?io. The set of letters Igor have now is {i, m}.
Finally, Oleg replaces the first question mark with 'o'. The company name becomes oio. The set of letters Oleg have now is {i}.
In the end, the company name is oio.
Oleg wants the company name to be as lexicographically small as possible while Igor wants the company name to be as lexicographically large as possible. What will be the company name if Oleg and Igor always play optimally?
A string s = s_1s_2...s_{m} is called lexicographically smaller than a string t = t_1t_2...t_{m} (where s β t) if s_{i} < t_{i} where i is the smallest index such that s_{i} β t_{i}. (so s_{j} = t_{j} for all j < i)
-----Input-----
The first line of input contains a string s of length n (1 β€ n β€ 3Β·10^5). All characters of the string are lowercase English letters. This string denotes the set of letters Oleg has initially.
The second line of input contains a string t of length n. All characters of the string are lowercase English letters. This string denotes the set of letters Igor has initially.
-----Output-----
The output should contain a string of n lowercase English letters, denoting the company name if Oleg and Igor plays optimally.
-----Examples-----
Input
tinkoff
zscoder
Output
fzfsirk
Input
xxxxxx
xxxxxx
Output
xxxxxx
Input
ioi
imo
Output
ioi
-----Note-----
One way to play optimally in the first sample is as follows : Initially, the company name is ???????. Oleg replaces the first question mark with 'f'. The company name becomes f??????. Igor replaces the second question mark with 'z'. The company name becomes fz?????. Oleg replaces the third question mark with 'f'. The company name becomes fzf????. Igor replaces the fourth question mark with 's'. The company name becomes fzfs???. Oleg replaces the fifth question mark with 'i'. The company name becomes fzfsi??. Igor replaces the sixth question mark with 'r'. The company name becomes fzfsir?. Oleg replaces the seventh question mark with 'k'. The company name becomes fzfsirk.
For the second sample, no matter how they play, the company name will always be xxxxxx.
|
s = input()
t = input()
n = len(s)
vs = [0] * 26
vt = vs[:]
for i in range(n):
vs[ord(s[i]) - 97] += 1
vt[ord(t[i]) - 97] += 1
ns = n // 2 + n % 2
nt = n // 2
cur = 0
starts = 0
ends = 0
for i in range(26):
if cur + vs[i] < ns:
cur += vs[i]
else:
vs[i] = ns - cur
cur = ns
ends = i
break
cur = 0
startt = 0
endt = 25
for i in range(25, -1, -1):
if cur + vt[i] < nt:
cur += vt[i]
else:
vt[i] = nt - cur
cur = nt
startt = i
break
res = ["*"] * n
start = 0
end = n - 1
for i in range(n):
while starts < 26 and vs[starts] == 0:
starts += 1
while ends >= 0 and vs[ends] == 0:
ends -= 1
while startt < 26 and vt[startt] == 0:
startt += 1
while endt >= 0 and vt[endt] == 0:
endt -= 1
while res[start] != "*":
start += 1
while res[end] != "*":
end -= 1
if i % 2 == 0:
if starts >= endt:
res[end] = chr(97 + ends)
vs[ends] -= 1
else:
res[start] = chr(97 + starts)
vs[starts] -= 1
elif endt <= starts:
res[end] = chr(97 + startt)
vt[startt] -= 1
else:
res[start] = chr(97 + endt)
vt[endt] -= 1
for i in range(n):
print(res[i], end="")
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR NUMBER VAR VAR NUMBER VAR NUMBER WHILE VAR NUMBER VAR VAR NUMBER VAR NUMBER WHILE VAR NUMBER VAR VAR NUMBER VAR NUMBER WHILE VAR NUMBER VAR VAR NUMBER VAR NUMBER WHILE VAR VAR STRING VAR NUMBER WHILE VAR VAR STRING VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
|
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company.
To settle this problem, they've decided to play a game. The company name will consist of n letters. Oleg and Igor each have a set of n letters (which might contain multiple copies of the same letter, the sets can be different). Initially, the company name is denoted by n question marks. Oleg and Igor takes turns to play the game, Oleg moves first. In each turn, a player can choose one of the letters c in his set and replace any of the question marks with c. Then, a copy of the letter c is removed from his set. The game ends when all the question marks has been replaced by some letter.
For example, suppose Oleg has the set of letters {i, o, i} and Igor has the set of letters {i, m, o}. One possible game is as follows :
Initially, the company name is ???.
Oleg replaces the second question mark with 'i'. The company name becomes ?i?. The set of letters Oleg have now is {i, o}.
Igor replaces the third question mark with 'o'. The company name becomes ?io. The set of letters Igor have now is {i, m}.
Finally, Oleg replaces the first question mark with 'o'. The company name becomes oio. The set of letters Oleg have now is {i}.
In the end, the company name is oio.
Oleg wants the company name to be as lexicographically small as possible while Igor wants the company name to be as lexicographically large as possible. What will be the company name if Oleg and Igor always play optimally?
A string s = s_1s_2...s_{m} is called lexicographically smaller than a string t = t_1t_2...t_{m} (where s β t) if s_{i} < t_{i} where i is the smallest index such that s_{i} β t_{i}. (so s_{j} = t_{j} for all j < i)
-----Input-----
The first line of input contains a string s of length n (1 β€ n β€ 3Β·10^5). All characters of the string are lowercase English letters. This string denotes the set of letters Oleg has initially.
The second line of input contains a string t of length n. All characters of the string are lowercase English letters. This string denotes the set of letters Igor has initially.
-----Output-----
The output should contain a string of n lowercase English letters, denoting the company name if Oleg and Igor plays optimally.
-----Examples-----
Input
tinkoff
zscoder
Output
fzfsirk
Input
xxxxxx
xxxxxx
Output
xxxxxx
Input
ioi
imo
Output
ioi
-----Note-----
One way to play optimally in the first sample is as follows : Initially, the company name is ???????. Oleg replaces the first question mark with 'f'. The company name becomes f??????. Igor replaces the second question mark with 'z'. The company name becomes fz?????. Oleg replaces the third question mark with 'f'. The company name becomes fzf????. Igor replaces the fourth question mark with 's'. The company name becomes fzfs???. Oleg replaces the fifth question mark with 'i'. The company name becomes fzfsi??. Igor replaces the sixth question mark with 'r'. The company name becomes fzfsir?. Oleg replaces the seventh question mark with 'k'. The company name becomes fzfsirk.
For the second sample, no matter how they play, the company name will always be xxxxxx.
|
s1 = input()
s2 = input()
n = len(s1)
s1 = sorted(s1)
s2 = sorted(s2)[::-1]
i = 0
j = 0
res = ["?"] * n
rear = n - 1
front = 0
Neven = n % 2 == 0
n1 = (n + 1) // 2 - 1
n2 = n // 2 - 1
for k in range(n):
if k % 2 == 0:
if s1[i] < s2[j]:
res[front] = s1[i]
front += 1
i += 1
else:
res[rear] = s1[n1]
rear -= 1
n1 -= 1
elif s1[i] < s2[j]:
res[front] = s2[j]
front += 1
j += 1
else:
res[rear] = s2[n2]
rear -= 1
n2 -= 1
print("".join(res))
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company.
To settle this problem, they've decided to play a game. The company name will consist of n letters. Oleg and Igor each have a set of n letters (which might contain multiple copies of the same letter, the sets can be different). Initially, the company name is denoted by n question marks. Oleg and Igor takes turns to play the game, Oleg moves first. In each turn, a player can choose one of the letters c in his set and replace any of the question marks with c. Then, a copy of the letter c is removed from his set. The game ends when all the question marks has been replaced by some letter.
For example, suppose Oleg has the set of letters {i, o, i} and Igor has the set of letters {i, m, o}. One possible game is as follows :
Initially, the company name is ???.
Oleg replaces the second question mark with 'i'. The company name becomes ?i?. The set of letters Oleg have now is {i, o}.
Igor replaces the third question mark with 'o'. The company name becomes ?io. The set of letters Igor have now is {i, m}.
Finally, Oleg replaces the first question mark with 'o'. The company name becomes oio. The set of letters Oleg have now is {i}.
In the end, the company name is oio.
Oleg wants the company name to be as lexicographically small as possible while Igor wants the company name to be as lexicographically large as possible. What will be the company name if Oleg and Igor always play optimally?
A string s = s_1s_2...s_{m} is called lexicographically smaller than a string t = t_1t_2...t_{m} (where s β t) if s_{i} < t_{i} where i is the smallest index such that s_{i} β t_{i}. (so s_{j} = t_{j} for all j < i)
-----Input-----
The first line of input contains a string s of length n (1 β€ n β€ 3Β·10^5). All characters of the string are lowercase English letters. This string denotes the set of letters Oleg has initially.
The second line of input contains a string t of length n. All characters of the string are lowercase English letters. This string denotes the set of letters Igor has initially.
-----Output-----
The output should contain a string of n lowercase English letters, denoting the company name if Oleg and Igor plays optimally.
-----Examples-----
Input
tinkoff
zscoder
Output
fzfsirk
Input
xxxxxx
xxxxxx
Output
xxxxxx
Input
ioi
imo
Output
ioi
-----Note-----
One way to play optimally in the first sample is as follows : Initially, the company name is ???????. Oleg replaces the first question mark with 'f'. The company name becomes f??????. Igor replaces the second question mark with 'z'. The company name becomes fz?????. Oleg replaces the third question mark with 'f'. The company name becomes fzf????. Igor replaces the fourth question mark with 's'. The company name becomes fzfs???. Oleg replaces the fifth question mark with 'i'. The company name becomes fzfsi??. Igor replaces the sixth question mark with 'r'. The company name becomes fzfsir?. Oleg replaces the seventh question mark with 'k'. The company name becomes fzfsirk.
For the second sample, no matter how they play, the company name will always be xxxxxx.
|
from sys import stdin, stdout
def rint():
return map(int, stdin.readline().split())
a = list(input())
b = list(input())
a.sort()
b.sort(reverse=True)
n = len(a)
ans = ["" for i in range(n)]
ai = 0
bi = 0
aj = 0
bj = 0
aiend = n // 2 - 1
if n % 2:
aiend += 1
biend = n // 2 - 1
i = 0
j = 0
flag = 0
while i + j < n:
if i + j < n:
if a[ai] < b[bi] and flag == 0:
ans[i] = a[ai]
i += 1
ai += 1
else:
ans[n - j - 1] = a[aiend - aj]
j += 1
aj += 1
flag = 1
if i + j < n:
if a[ai] < b[bi] and flag == 0:
ans[i] = b[bi]
i += 1
bi += 1
else:
ans[n - j - 1] = b[biend - bj]
j += 1
bj += 1
flag = 1
print("".join(ans))
|
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR STRING VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company.
To settle this problem, they've decided to play a game. The company name will consist of n letters. Oleg and Igor each have a set of n letters (which might contain multiple copies of the same letter, the sets can be different). Initially, the company name is denoted by n question marks. Oleg and Igor takes turns to play the game, Oleg moves first. In each turn, a player can choose one of the letters c in his set and replace any of the question marks with c. Then, a copy of the letter c is removed from his set. The game ends when all the question marks has been replaced by some letter.
For example, suppose Oleg has the set of letters {i, o, i} and Igor has the set of letters {i, m, o}. One possible game is as follows :
Initially, the company name is ???.
Oleg replaces the second question mark with 'i'. The company name becomes ?i?. The set of letters Oleg have now is {i, o}.
Igor replaces the third question mark with 'o'. The company name becomes ?io. The set of letters Igor have now is {i, m}.
Finally, Oleg replaces the first question mark with 'o'. The company name becomes oio. The set of letters Oleg have now is {i}.
In the end, the company name is oio.
Oleg wants the company name to be as lexicographically small as possible while Igor wants the company name to be as lexicographically large as possible. What will be the company name if Oleg and Igor always play optimally?
A string s = s_1s_2...s_{m} is called lexicographically smaller than a string t = t_1t_2...t_{m} (where s β t) if s_{i} < t_{i} where i is the smallest index such that s_{i} β t_{i}. (so s_{j} = t_{j} for all j < i)
-----Input-----
The first line of input contains a string s of length n (1 β€ n β€ 3Β·10^5). All characters of the string are lowercase English letters. This string denotes the set of letters Oleg has initially.
The second line of input contains a string t of length n. All characters of the string are lowercase English letters. This string denotes the set of letters Igor has initially.
-----Output-----
The output should contain a string of n lowercase English letters, denoting the company name if Oleg and Igor plays optimally.
-----Examples-----
Input
tinkoff
zscoder
Output
fzfsirk
Input
xxxxxx
xxxxxx
Output
xxxxxx
Input
ioi
imo
Output
ioi
-----Note-----
One way to play optimally in the first sample is as follows : Initially, the company name is ???????. Oleg replaces the first question mark with 'f'. The company name becomes f??????. Igor replaces the second question mark with 'z'. The company name becomes fz?????. Oleg replaces the third question mark with 'f'. The company name becomes fzf????. Igor replaces the fourth question mark with 's'. The company name becomes fzfs???. Oleg replaces the fifth question mark with 'i'. The company name becomes fzfsi??. Igor replaces the sixth question mark with 'r'. The company name becomes fzfsir?. Oleg replaces the seventh question mark with 'k'. The company name becomes fzfsirk.
For the second sample, no matter how they play, the company name will always be xxxxxx.
|
from sys import *
f = lambda: sorted(stdin.readline()[:-1])
t = [f()[::-1], f()]
n = len(t[0])
p = [n & 1, 1]
s = ""
for i in range(n):
k = t[0][-1] < t[1][-1]
p[k] ^= 1
s += t[p[k]].pop()
print(s)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR LIST FUNC_CALL VAR NUMBER FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST BIN_OP VAR NUMBER NUMBER ASSIGN VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER VAR NUMBER NUMBER VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR
|
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company.
To settle this problem, they've decided to play a game. The company name will consist of n letters. Oleg and Igor each have a set of n letters (which might contain multiple copies of the same letter, the sets can be different). Initially, the company name is denoted by n question marks. Oleg and Igor takes turns to play the game, Oleg moves first. In each turn, a player can choose one of the letters c in his set and replace any of the question marks with c. Then, a copy of the letter c is removed from his set. The game ends when all the question marks has been replaced by some letter.
For example, suppose Oleg has the set of letters {i, o, i} and Igor has the set of letters {i, m, o}. One possible game is as follows :
Initially, the company name is ???.
Oleg replaces the second question mark with 'i'. The company name becomes ?i?. The set of letters Oleg have now is {i, o}.
Igor replaces the third question mark with 'o'. The company name becomes ?io. The set of letters Igor have now is {i, m}.
Finally, Oleg replaces the first question mark with 'o'. The company name becomes oio. The set of letters Oleg have now is {i}.
In the end, the company name is oio.
Oleg wants the company name to be as lexicographically small as possible while Igor wants the company name to be as lexicographically large as possible. What will be the company name if Oleg and Igor always play optimally?
A string s = s_1s_2...s_{m} is called lexicographically smaller than a string t = t_1t_2...t_{m} (where s β t) if s_{i} < t_{i} where i is the smallest index such that s_{i} β t_{i}. (so s_{j} = t_{j} for all j < i)
-----Input-----
The first line of input contains a string s of length n (1 β€ n β€ 3Β·10^5). All characters of the string are lowercase English letters. This string denotes the set of letters Oleg has initially.
The second line of input contains a string t of length n. All characters of the string are lowercase English letters. This string denotes the set of letters Igor has initially.
-----Output-----
The output should contain a string of n lowercase English letters, denoting the company name if Oleg and Igor plays optimally.
-----Examples-----
Input
tinkoff
zscoder
Output
fzfsirk
Input
xxxxxx
xxxxxx
Output
xxxxxx
Input
ioi
imo
Output
ioi
-----Note-----
One way to play optimally in the first sample is as follows : Initially, the company name is ???????. Oleg replaces the first question mark with 'f'. The company name becomes f??????. Igor replaces the second question mark with 'z'. The company name becomes fz?????. Oleg replaces the third question mark with 'f'. The company name becomes fzf????. Igor replaces the fourth question mark with 's'. The company name becomes fzfs???. Oleg replaces the fifth question mark with 'i'. The company name becomes fzfsi??. Igor replaces the sixth question mark with 'r'. The company name becomes fzfsir?. Oleg replaces the seventh question mark with 'k'. The company name becomes fzfsirk.
For the second sample, no matter how they play, the company name will always be xxxxxx.
|
from sys import *
f = lambda: sorted(stdin.readline()[:-1])
a, b = f(), f()
n = len(a)
u = v = ""
i, j = 0, -1
x, y = n - 1 >> 1, n - 2 >> 1
while x != -1:
if a[i] < b[j]:
u += a[i]
i += 1
else:
v += a[i + x]
x -= 1
if y == -1:
break
elif a[i] < b[j]:
u += b[j]
j -= 1
else:
v += b[j - y]
y -= 1
print(u + v[::-1])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER WHILE VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR VAR NUMBER IF VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR NUMBER VAR VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER
|
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company.
To settle this problem, they've decided to play a game. The company name will consist of n letters. Oleg and Igor each have a set of n letters (which might contain multiple copies of the same letter, the sets can be different). Initially, the company name is denoted by n question marks. Oleg and Igor takes turns to play the game, Oleg moves first. In each turn, a player can choose one of the letters c in his set and replace any of the question marks with c. Then, a copy of the letter c is removed from his set. The game ends when all the question marks has been replaced by some letter.
For example, suppose Oleg has the set of letters {i, o, i} and Igor has the set of letters {i, m, o}. One possible game is as follows :
Initially, the company name is ???.
Oleg replaces the second question mark with 'i'. The company name becomes ?i?. The set of letters Oleg have now is {i, o}.
Igor replaces the third question mark with 'o'. The company name becomes ?io. The set of letters Igor have now is {i, m}.
Finally, Oleg replaces the first question mark with 'o'. The company name becomes oio. The set of letters Oleg have now is {i}.
In the end, the company name is oio.
Oleg wants the company name to be as lexicographically small as possible while Igor wants the company name to be as lexicographically large as possible. What will be the company name if Oleg and Igor always play optimally?
A string s = s_1s_2...s_{m} is called lexicographically smaller than a string t = t_1t_2...t_{m} (where s β t) if s_{i} < t_{i} where i is the smallest index such that s_{i} β t_{i}. (so s_{j} = t_{j} for all j < i)
-----Input-----
The first line of input contains a string s of length n (1 β€ n β€ 3Β·10^5). All characters of the string are lowercase English letters. This string denotes the set of letters Oleg has initially.
The second line of input contains a string t of length n. All characters of the string are lowercase English letters. This string denotes the set of letters Igor has initially.
-----Output-----
The output should contain a string of n lowercase English letters, denoting the company name if Oleg and Igor plays optimally.
-----Examples-----
Input
tinkoff
zscoder
Output
fzfsirk
Input
xxxxxx
xxxxxx
Output
xxxxxx
Input
ioi
imo
Output
ioi
-----Note-----
One way to play optimally in the first sample is as follows : Initially, the company name is ???????. Oleg replaces the first question mark with 'f'. The company name becomes f??????. Igor replaces the second question mark with 'z'. The company name becomes fz?????. Oleg replaces the third question mark with 'f'. The company name becomes fzf????. Igor replaces the fourth question mark with 's'. The company name becomes fzfs???. Oleg replaces the fifth question mark with 'i'. The company name becomes fzfsi??. Igor replaces the sixth question mark with 'r'. The company name becomes fzfsir?. Oleg replaces the seventh question mark with 'k'. The company name becomes fzfsirk.
For the second sample, no matter how they play, the company name will always be xxxxxx.
|
from sys import stdin, stdout
a = stdin.readline().rstrip()
b = stdin.readline().rstrip()
a_count = 26 * [0]
b_count = 26 * [0]
length = len(a)
for i in range(length):
a_count[ord(a[i]) - ord("a")] += 1
b_count[ord(b[i]) - ord("a")] += 1
result = length * ["a"]
left = 0
right = length - 1
mina, minb, maxa, maxb = 0, 0, 25, 25
exclude = length // 2
for i in range(25, -1, -1):
if exclude <= 0:
break
while exclude > 0 and a_count[i] != 0:
exclude -= 1
a_count[i] -= 1
exclude = (length + 1) // 2
for i in range(26):
if exclude <= 0:
break
while exclude > 0 and b_count[i] != 0:
exclude -= 1
b_count[i] -= 1
while a_count[mina] == 0 and mina < 25:
mina += 1
while b_count[minb] == 0 and minb < 25:
minb += 1
while a_count[maxa] == 0 and maxa > 0:
maxa -= 1
while b_count[maxb] == 0 and maxb > 0:
maxb -= 1
i = 0
while i < length:
if i & 1 == 0:
if mina < maxb:
result[left] = chr(ord("a") + mina)
left += 1
a_count[mina] -= 1
while a_count[mina] == 0 and mina < 25:
mina += 1
else:
result[right] = chr(ord("a") + maxa)
right -= 1
a_count[maxa] -= 1
while a_count[maxa] == 0 and maxa > 0:
maxa -= 1
elif mina < maxb:
result[left] = chr(ord("a") + maxb)
left += 1
b_count[maxb] -= 1
while b_count[maxb] == 0 and maxb > 0:
maxb -= 1
else:
result[right] = chr(ord("a") + minb)
right -= 1
b_count[minb] -= 1
while b_count[minb] == 0 and minb < 25:
minb += 1
i += 1
print("".join(result))
|
ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER LIST NUMBER ASSIGN VAR BIN_OP NUMBER LIST NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING NUMBER ASSIGN VAR BIN_OP VAR LIST STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER NUMBER IF VAR NUMBER WHILE VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR NUMBER WHILE VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR VAR NUMBER VAR VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR VAR NUMBER VAR VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR VAR NUMBER VAR VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR STRING VAR VAR NUMBER VAR VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company.
To settle this problem, they've decided to play a game. The company name will consist of n letters. Oleg and Igor each have a set of n letters (which might contain multiple copies of the same letter, the sets can be different). Initially, the company name is denoted by n question marks. Oleg and Igor takes turns to play the game, Oleg moves first. In each turn, a player can choose one of the letters c in his set and replace any of the question marks with c. Then, a copy of the letter c is removed from his set. The game ends when all the question marks has been replaced by some letter.
For example, suppose Oleg has the set of letters {i, o, i} and Igor has the set of letters {i, m, o}. One possible game is as follows :
Initially, the company name is ???.
Oleg replaces the second question mark with 'i'. The company name becomes ?i?. The set of letters Oleg have now is {i, o}.
Igor replaces the third question mark with 'o'. The company name becomes ?io. The set of letters Igor have now is {i, m}.
Finally, Oleg replaces the first question mark with 'o'. The company name becomes oio. The set of letters Oleg have now is {i}.
In the end, the company name is oio.
Oleg wants the company name to be as lexicographically small as possible while Igor wants the company name to be as lexicographically large as possible. What will be the company name if Oleg and Igor always play optimally?
A string s = s_1s_2...s_{m} is called lexicographically smaller than a string t = t_1t_2...t_{m} (where s β t) if s_{i} < t_{i} where i is the smallest index such that s_{i} β t_{i}. (so s_{j} = t_{j} for all j < i)
-----Input-----
The first line of input contains a string s of length n (1 β€ n β€ 3Β·10^5). All characters of the string are lowercase English letters. This string denotes the set of letters Oleg has initially.
The second line of input contains a string t of length n. All characters of the string are lowercase English letters. This string denotes the set of letters Igor has initially.
-----Output-----
The output should contain a string of n lowercase English letters, denoting the company name if Oleg and Igor plays optimally.
-----Examples-----
Input
tinkoff
zscoder
Output
fzfsirk
Input
xxxxxx
xxxxxx
Output
xxxxxx
Input
ioi
imo
Output
ioi
-----Note-----
One way to play optimally in the first sample is as follows : Initially, the company name is ???????. Oleg replaces the first question mark with 'f'. The company name becomes f??????. Igor replaces the second question mark with 'z'. The company name becomes fz?????. Oleg replaces the third question mark with 'f'. The company name becomes fzf????. Igor replaces the fourth question mark with 's'. The company name becomes fzfs???. Oleg replaces the fifth question mark with 'i'. The company name becomes fzfsi??. Igor replaces the sixth question mark with 'r'. The company name becomes fzfsir?. Oleg replaces the seventh question mark with 'k'. The company name becomes fzfsirk.
For the second sample, no matter how they play, the company name will always be xxxxxx.
|
oleg = input()
igor = input()
oleg = sorted(list(oleg))
igor = sorted(list(igor))
n = len(oleg)
oleg_turns = (n + 1) // 2
igor_turns = n // 2
min_oleg_id = 0
min_igor_id = n - igor_turns
ans = ["?"] * n
max_oleg_id = oleg_turns - 1
max_igor_id = n - 1
curr_turn = "o"
next_turn = {"o": "i", "i": "o"}
l_ans = 0
r_ans = n - 1
while r_ans >= l_ans:
if curr_turn == "o":
if oleg[min_oleg_id] < igor[max_igor_id]:
ans[l_ans] = oleg[min_oleg_id]
l_ans += 1
min_oleg_id += 1
else:
ans[r_ans] = oleg[max_oleg_id]
r_ans += -1
max_oleg_id += -1
curr_turn = "i"
else:
if igor[max_igor_id] > oleg[min_oleg_id]:
ans[l_ans] = igor[max_igor_id]
l_ans += 1
max_igor_id += -1
else:
ans[r_ans] = igor[min_igor_id]
r_ans += -1
min_igor_id += 1
curr_turn = "o"
strans = "".join(ans)
print(strans)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR STRING ASSIGN VAR DICT STRING STRING STRING STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR IF VAR STRING IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR STRING IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR STRING ASSIGN VAR FUNC_CALL STRING VAR EXPR FUNC_CALL VAR VAR
|
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company.
To settle this problem, they've decided to play a game. The company name will consist of n letters. Oleg and Igor each have a set of n letters (which might contain multiple copies of the same letter, the sets can be different). Initially, the company name is denoted by n question marks. Oleg and Igor takes turns to play the game, Oleg moves first. In each turn, a player can choose one of the letters c in his set and replace any of the question marks with c. Then, a copy of the letter c is removed from his set. The game ends when all the question marks has been replaced by some letter.
For example, suppose Oleg has the set of letters {i, o, i} and Igor has the set of letters {i, m, o}. One possible game is as follows :
Initially, the company name is ???.
Oleg replaces the second question mark with 'i'. The company name becomes ?i?. The set of letters Oleg have now is {i, o}.
Igor replaces the third question mark with 'o'. The company name becomes ?io. The set of letters Igor have now is {i, m}.
Finally, Oleg replaces the first question mark with 'o'. The company name becomes oio. The set of letters Oleg have now is {i}.
In the end, the company name is oio.
Oleg wants the company name to be as lexicographically small as possible while Igor wants the company name to be as lexicographically large as possible. What will be the company name if Oleg and Igor always play optimally?
A string s = s_1s_2...s_{m} is called lexicographically smaller than a string t = t_1t_2...t_{m} (where s β t) if s_{i} < t_{i} where i is the smallest index such that s_{i} β t_{i}. (so s_{j} = t_{j} for all j < i)
-----Input-----
The first line of input contains a string s of length n (1 β€ n β€ 3Β·10^5). All characters of the string are lowercase English letters. This string denotes the set of letters Oleg has initially.
The second line of input contains a string t of length n. All characters of the string are lowercase English letters. This string denotes the set of letters Igor has initially.
-----Output-----
The output should contain a string of n lowercase English letters, denoting the company name if Oleg and Igor plays optimally.
-----Examples-----
Input
tinkoff
zscoder
Output
fzfsirk
Input
xxxxxx
xxxxxx
Output
xxxxxx
Input
ioi
imo
Output
ioi
-----Note-----
One way to play optimally in the first sample is as follows : Initially, the company name is ???????. Oleg replaces the first question mark with 'f'. The company name becomes f??????. Igor replaces the second question mark with 'z'. The company name becomes fz?????. Oleg replaces the third question mark with 'f'. The company name becomes fzf????. Igor replaces the fourth question mark with 's'. The company name becomes fzfs???. Oleg replaces the fifth question mark with 'i'. The company name becomes fzfsi??. Igor replaces the sixth question mark with 'r'. The company name becomes fzfsir?. Oleg replaces the seventh question mark with 'k'. The company name becomes fzfsirk.
For the second sample, no matter how they play, the company name will always be xxxxxx.
|
a = list(input())
b = list(input())
name = [None for _ in range(len(a))]
a.sort()
b.sort(reverse=True)
ai = 0
aj = (len(a) + 1) // 2 - 1
bi = 0
bj = len(b) // 2 - 1
turn = 0
ansi = 0
ansj = len(name) - 1
for _ in range(len(name)):
if not turn:
if a[ai] < b[bi]:
name[ansi] = a[ai]
ai += 1
ansi += 1
else:
name[ansj] = a[aj]
aj -= 1
ansj -= 1
elif b[bi] > a[ai]:
name[ansi] = b[bi]
bi += 1
ansi += 1
else:
name[ansj] = b[bj]
bj -= 1
ansj -= 1
turn ^= 1
print("".join(name))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NONE VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company.
To settle this problem, they've decided to play a game. The company name will consist of n letters. Oleg and Igor each have a set of n letters (which might contain multiple copies of the same letter, the sets can be different). Initially, the company name is denoted by n question marks. Oleg and Igor takes turns to play the game, Oleg moves first. In each turn, a player can choose one of the letters c in his set and replace any of the question marks with c. Then, a copy of the letter c is removed from his set. The game ends when all the question marks has been replaced by some letter.
For example, suppose Oleg has the set of letters {i, o, i} and Igor has the set of letters {i, m, o}. One possible game is as follows :
Initially, the company name is ???.
Oleg replaces the second question mark with 'i'. The company name becomes ?i?. The set of letters Oleg have now is {i, o}.
Igor replaces the third question mark with 'o'. The company name becomes ?io. The set of letters Igor have now is {i, m}.
Finally, Oleg replaces the first question mark with 'o'. The company name becomes oio. The set of letters Oleg have now is {i}.
In the end, the company name is oio.
Oleg wants the company name to be as lexicographically small as possible while Igor wants the company name to be as lexicographically large as possible. What will be the company name if Oleg and Igor always play optimally?
A string s = s_1s_2...s_{m} is called lexicographically smaller than a string t = t_1t_2...t_{m} (where s β t) if s_{i} < t_{i} where i is the smallest index such that s_{i} β t_{i}. (so s_{j} = t_{j} for all j < i)
-----Input-----
The first line of input contains a string s of length n (1 β€ n β€ 3Β·10^5). All characters of the string are lowercase English letters. This string denotes the set of letters Oleg has initially.
The second line of input contains a string t of length n. All characters of the string are lowercase English letters. This string denotes the set of letters Igor has initially.
-----Output-----
The output should contain a string of n lowercase English letters, denoting the company name if Oleg and Igor plays optimally.
-----Examples-----
Input
tinkoff
zscoder
Output
fzfsirk
Input
xxxxxx
xxxxxx
Output
xxxxxx
Input
ioi
imo
Output
ioi
-----Note-----
One way to play optimally in the first sample is as follows : Initially, the company name is ???????. Oleg replaces the first question mark with 'f'. The company name becomes f??????. Igor replaces the second question mark with 'z'. The company name becomes fz?????. Oleg replaces the third question mark with 'f'. The company name becomes fzf????. Igor replaces the fourth question mark with 's'. The company name becomes fzfs???. Oleg replaces the fifth question mark with 'i'. The company name becomes fzfsi??. Igor replaces the sixth question mark with 'r'. The company name becomes fzfsir?. Oleg replaces the seventh question mark with 'k'. The company name becomes fzfsirk.
For the second sample, no matter how they play, the company name will always be xxxxxx.
|
s = input()
s1 = input()
n = len(s1)
sl = []
sl1 = []
for i in range(n):
sl += [s[i]]
sl1 += [s1[i]]
ans = sl1[:]
sl1.sort()
sl.sort()
sl1.reverse()
i = 0
i2 = (n - 1) // 2
k = 0
k2 = n // 2 - 1
j = len(s) - 1
temp = 0
for x in range(len(s1)):
if x % 2 == 0:
if sl[i] < sl1[k]:
ans[temp] = sl[i]
temp += 1
i += 1
elif sl[i] >= sl1[k]:
ans[j] = sl[i2]
i2 -= 1
j -= 1
if x % 2 == 1:
if sl[i] < sl1[k]:
ans[temp] = sl1[k]
temp += 1
k += 1
elif sl[i] >= sl1[k]:
ans[j] = sl1[k2]
j -= 1
k2 -= 1
print("".join(ans))
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR VAR LIST VAR VAR VAR LIST VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company.
To settle this problem, they've decided to play a game. The company name will consist of n letters. Oleg and Igor each have a set of n letters (which might contain multiple copies of the same letter, the sets can be different). Initially, the company name is denoted by n question marks. Oleg and Igor takes turns to play the game, Oleg moves first. In each turn, a player can choose one of the letters c in his set and replace any of the question marks with c. Then, a copy of the letter c is removed from his set. The game ends when all the question marks has been replaced by some letter.
For example, suppose Oleg has the set of letters {i, o, i} and Igor has the set of letters {i, m, o}. One possible game is as follows :
Initially, the company name is ???.
Oleg replaces the second question mark with 'i'. The company name becomes ?i?. The set of letters Oleg have now is {i, o}.
Igor replaces the third question mark with 'o'. The company name becomes ?io. The set of letters Igor have now is {i, m}.
Finally, Oleg replaces the first question mark with 'o'. The company name becomes oio. The set of letters Oleg have now is {i}.
In the end, the company name is oio.
Oleg wants the company name to be as lexicographically small as possible while Igor wants the company name to be as lexicographically large as possible. What will be the company name if Oleg and Igor always play optimally?
A string s = s_1s_2...s_{m} is called lexicographically smaller than a string t = t_1t_2...t_{m} (where s β t) if s_{i} < t_{i} where i is the smallest index such that s_{i} β t_{i}. (so s_{j} = t_{j} for all j < i)
-----Input-----
The first line of input contains a string s of length n (1 β€ n β€ 3Β·10^5). All characters of the string are lowercase English letters. This string denotes the set of letters Oleg has initially.
The second line of input contains a string t of length n. All characters of the string are lowercase English letters. This string denotes the set of letters Igor has initially.
-----Output-----
The output should contain a string of n lowercase English letters, denoting the company name if Oleg and Igor plays optimally.
-----Examples-----
Input
tinkoff
zscoder
Output
fzfsirk
Input
xxxxxx
xxxxxx
Output
xxxxxx
Input
ioi
imo
Output
ioi
-----Note-----
One way to play optimally in the first sample is as follows : Initially, the company name is ???????. Oleg replaces the first question mark with 'f'. The company name becomes f??????. Igor replaces the second question mark with 'z'. The company name becomes fz?????. Oleg replaces the third question mark with 'f'. The company name becomes fzf????. Igor replaces the fourth question mark with 's'. The company name becomes fzfs???. Oleg replaces the fifth question mark with 'i'. The company name becomes fzfsi??. Igor replaces the sixth question mark with 'r'. The company name becomes fzfsir?. Oleg replaces the seventh question mark with 'k'. The company name becomes fzfsirk.
For the second sample, no matter how they play, the company name will always be xxxxxx.
|
import sys
def main():
s = sys.stdin.readline().rstrip()
t = sys.stdin.readline().rstrip()
result = []
iisl = 0
iisr = len(s) // 2 + len(s) % 2 - 1
iitl = 0
iitr = len(s) // 2 - 1
aas = list(sorted(list(s)))
aat = list(sorted(list(t), reverse=True))
rl = 0
rr = len(s) - 1
result = ["?"] * len(s)
for i in range(len(s)):
if i % 2 == 0:
if aas[iisl] < aat[iitl]:
result[rl] = aas[iisl]
iisl += 1
rl += 1
else:
result[rr] = aas[iisr]
iisr -= 1
rr -= 1
elif aat[iitl] > aas[iisl]:
result[rl] = aat[iitl]
iitl += 1
rl += 1
else:
result[rr] = aat[iitr]
iitr -= 1
rr -= 1
sys.stdout.write("".join(result) + "\n")
main()
|
IMPORT FUNC_DEF ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST STRING FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL STRING VAR STRING EXPR FUNC_CALL VAR
|
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company.
To settle this problem, they've decided to play a game. The company name will consist of n letters. Oleg and Igor each have a set of n letters (which might contain multiple copies of the same letter, the sets can be different). Initially, the company name is denoted by n question marks. Oleg and Igor takes turns to play the game, Oleg moves first. In each turn, a player can choose one of the letters c in his set and replace any of the question marks with c. Then, a copy of the letter c is removed from his set. The game ends when all the question marks has been replaced by some letter.
For example, suppose Oleg has the set of letters {i, o, i} and Igor has the set of letters {i, m, o}. One possible game is as follows :
Initially, the company name is ???.
Oleg replaces the second question mark with 'i'. The company name becomes ?i?. The set of letters Oleg have now is {i, o}.
Igor replaces the third question mark with 'o'. The company name becomes ?io. The set of letters Igor have now is {i, m}.
Finally, Oleg replaces the first question mark with 'o'. The company name becomes oio. The set of letters Oleg have now is {i}.
In the end, the company name is oio.
Oleg wants the company name to be as lexicographically small as possible while Igor wants the company name to be as lexicographically large as possible. What will be the company name if Oleg and Igor always play optimally?
A string s = s_1s_2...s_{m} is called lexicographically smaller than a string t = t_1t_2...t_{m} (where s β t) if s_{i} < t_{i} where i is the smallest index such that s_{i} β t_{i}. (so s_{j} = t_{j} for all j < i)
-----Input-----
The first line of input contains a string s of length n (1 β€ n β€ 3Β·10^5). All characters of the string are lowercase English letters. This string denotes the set of letters Oleg has initially.
The second line of input contains a string t of length n. All characters of the string are lowercase English letters. This string denotes the set of letters Igor has initially.
-----Output-----
The output should contain a string of n lowercase English letters, denoting the company name if Oleg and Igor plays optimally.
-----Examples-----
Input
tinkoff
zscoder
Output
fzfsirk
Input
xxxxxx
xxxxxx
Output
xxxxxx
Input
ioi
imo
Output
ioi
-----Note-----
One way to play optimally in the first sample is as follows : Initially, the company name is ???????. Oleg replaces the first question mark with 'f'. The company name becomes f??????. Igor replaces the second question mark with 'z'. The company name becomes fz?????. Oleg replaces the third question mark with 'f'. The company name becomes fzf????. Igor replaces the fourth question mark with 's'. The company name becomes fzfs???. Oleg replaces the fifth question mark with 'i'. The company name becomes fzfsi??. Igor replaces the sixth question mark with 'r'. The company name becomes fzfsir?. Oleg replaces the seventh question mark with 'k'. The company name becomes fzfsirk.
For the second sample, no matter how they play, the company name will always be xxxxxx.
|
a = list(input())
b = list(input())
n = len(a)
if len(a) == 1:
print(a[0])
return
a.sort()
b.sort()
a = a[: (len(a) + 1) // 2]
if n % 2 == 1:
b = b[len(b) // 2 + 1 :]
else:
b = b[len(b) // 2 :]
sa = 0
ea = len(a) - 1
sb = 0
eb = len(b) - 1
stb = 0
ste = n - 1
st = [""] * n
for i in range(n):
if i % 2 == 0:
if a[sa] < b[eb]:
st[stb] = a[sa]
sa += 1
stb += 1
else:
st[ste] = a[ea]
ea -= 1
ste -= 1
else:
if eb == sb and n % 2 == 0:
st[stb] = b[eb]
break
if b[eb] > a[sa]:
st[stb] = b[eb]
eb -= 1
stb += 1
else:
st[ste] = b[sb]
ste -= 1
sb += 1
for i in range(len(st)):
print(st[i], end="")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR NUMBER RETURN EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST STRING VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING
|
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company.
To settle this problem, they've decided to play a game. The company name will consist of n letters. Oleg and Igor each have a set of n letters (which might contain multiple copies of the same letter, the sets can be different). Initially, the company name is denoted by n question marks. Oleg and Igor takes turns to play the game, Oleg moves first. In each turn, a player can choose one of the letters c in his set and replace any of the question marks with c. Then, a copy of the letter c is removed from his set. The game ends when all the question marks has been replaced by some letter.
For example, suppose Oleg has the set of letters {i, o, i} and Igor has the set of letters {i, m, o}. One possible game is as follows :
Initially, the company name is ???.
Oleg replaces the second question mark with 'i'. The company name becomes ?i?. The set of letters Oleg have now is {i, o}.
Igor replaces the third question mark with 'o'. The company name becomes ?io. The set of letters Igor have now is {i, m}.
Finally, Oleg replaces the first question mark with 'o'. The company name becomes oio. The set of letters Oleg have now is {i}.
In the end, the company name is oio.
Oleg wants the company name to be as lexicographically small as possible while Igor wants the company name to be as lexicographically large as possible. What will be the company name if Oleg and Igor always play optimally?
A string s = s_1s_2...s_{m} is called lexicographically smaller than a string t = t_1t_2...t_{m} (where s β t) if s_{i} < t_{i} where i is the smallest index such that s_{i} β t_{i}. (so s_{j} = t_{j} for all j < i)
-----Input-----
The first line of input contains a string s of length n (1 β€ n β€ 3Β·10^5). All characters of the string are lowercase English letters. This string denotes the set of letters Oleg has initially.
The second line of input contains a string t of length n. All characters of the string are lowercase English letters. This string denotes the set of letters Igor has initially.
-----Output-----
The output should contain a string of n lowercase English letters, denoting the company name if Oleg and Igor plays optimally.
-----Examples-----
Input
tinkoff
zscoder
Output
fzfsirk
Input
xxxxxx
xxxxxx
Output
xxxxxx
Input
ioi
imo
Output
ioi
-----Note-----
One way to play optimally in the first sample is as follows : Initially, the company name is ???????. Oleg replaces the first question mark with 'f'. The company name becomes f??????. Igor replaces the second question mark with 'z'. The company name becomes fz?????. Oleg replaces the third question mark with 'f'. The company name becomes fzf????. Igor replaces the fourth question mark with 's'. The company name becomes fzfs???. Oleg replaces the fifth question mark with 'i'. The company name becomes fzfsi??. Igor replaces the sixth question mark with 'r'. The company name becomes fzfsir?. Oleg replaces the seventh question mark with 'k'. The company name becomes fzfsirk.
For the second sample, no matter how they play, the company name will always be xxxxxx.
|
a = list(input())
b = list(input())
a.sort()
b.sort(reverse=True)
ans = list()
for i in a:
ans.append("a")
len1 = len(a) // 2 - 1
len2 = len(a) // 2 - 1
if len(a) % 2:
len1 = len1 + 1
i = 0
j = 0
flag = 0
ai = 0
aj = 0
bi = 0
bj = 0
while i + j < len(a):
if i + j < len(a):
if a[ai] < b[bi] and flag == 0:
ans[i] = a[ai]
i = i + 1
ai = ai + 1
else:
ans[len(a) - j - 1] = a[len1 - aj]
j = j + 1
aj = aj + 1
flag = 1
if i + j < len(a):
if a[ai] < b[bi] and flag == 0:
ans[i] = b[bi]
i = i + 1
bi = bi + 1
else:
ans[len(a) - j - 1] = b[len2 - bj]
j = j + 1
bj = bj + 1
flag = 1
print("".join(ans))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company.
To settle this problem, they've decided to play a game. The company name will consist of n letters. Oleg and Igor each have a set of n letters (which might contain multiple copies of the same letter, the sets can be different). Initially, the company name is denoted by n question marks. Oleg and Igor takes turns to play the game, Oleg moves first. In each turn, a player can choose one of the letters c in his set and replace any of the question marks with c. Then, a copy of the letter c is removed from his set. The game ends when all the question marks has been replaced by some letter.
For example, suppose Oleg has the set of letters {i, o, i} and Igor has the set of letters {i, m, o}. One possible game is as follows :
Initially, the company name is ???.
Oleg replaces the second question mark with 'i'. The company name becomes ?i?. The set of letters Oleg have now is {i, o}.
Igor replaces the third question mark with 'o'. The company name becomes ?io. The set of letters Igor have now is {i, m}.
Finally, Oleg replaces the first question mark with 'o'. The company name becomes oio. The set of letters Oleg have now is {i}.
In the end, the company name is oio.
Oleg wants the company name to be as lexicographically small as possible while Igor wants the company name to be as lexicographically large as possible. What will be the company name if Oleg and Igor always play optimally?
A string s = s_1s_2...s_{m} is called lexicographically smaller than a string t = t_1t_2...t_{m} (where s β t) if s_{i} < t_{i} where i is the smallest index such that s_{i} β t_{i}. (so s_{j} = t_{j} for all j < i)
-----Input-----
The first line of input contains a string s of length n (1 β€ n β€ 3Β·10^5). All characters of the string are lowercase English letters. This string denotes the set of letters Oleg has initially.
The second line of input contains a string t of length n. All characters of the string are lowercase English letters. This string denotes the set of letters Igor has initially.
-----Output-----
The output should contain a string of n lowercase English letters, denoting the company name if Oleg and Igor plays optimally.
-----Examples-----
Input
tinkoff
zscoder
Output
fzfsirk
Input
xxxxxx
xxxxxx
Output
xxxxxx
Input
ioi
imo
Output
ioi
-----Note-----
One way to play optimally in the first sample is as follows : Initially, the company name is ???????. Oleg replaces the first question mark with 'f'. The company name becomes f??????. Igor replaces the second question mark with 'z'. The company name becomes fz?????. Oleg replaces the third question mark with 'f'. The company name becomes fzf????. Igor replaces the fourth question mark with 's'. The company name becomes fzfs???. Oleg replaces the fifth question mark with 'i'. The company name becomes fzfsi??. Igor replaces the sixth question mark with 'r'. The company name becomes fzfsir?. Oleg replaces the seventh question mark with 'k'. The company name becomes fzfsirk.
For the second sample, no matter how they play, the company name will always be xxxxxx.
|
s1 = list(input())
s2 = list(input())
s1.sort()
s2.sort(reverse=True)
n = len(s1)
s = ["?"] * n
i, j, ni, nj = 0, 0, (n + 1) // 2 - 1, n // 2 - 1
front, rear = 0, n - 1
for cur in range(n):
if cur & 1 == 0:
if s1[i] < s2[j]:
s[front] = s1[i]
i += 1
front += 1
else:
s[rear] = s1[ni]
ni -= 1
rear -= 1
elif s1[i] < s2[j]:
s[front] = s2[j]
j += 1
front += 1
else:
s[rear] = s2[nj]
nj -= 1
rear -= 1
print("".join(s))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST STRING VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER BIN_OP BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company.
To settle this problem, they've decided to play a game. The company name will consist of n letters. Oleg and Igor each have a set of n letters (which might contain multiple copies of the same letter, the sets can be different). Initially, the company name is denoted by n question marks. Oleg and Igor takes turns to play the game, Oleg moves first. In each turn, a player can choose one of the letters c in his set and replace any of the question marks with c. Then, a copy of the letter c is removed from his set. The game ends when all the question marks has been replaced by some letter.
For example, suppose Oleg has the set of letters {i, o, i} and Igor has the set of letters {i, m, o}. One possible game is as follows :
Initially, the company name is ???.
Oleg replaces the second question mark with 'i'. The company name becomes ?i?. The set of letters Oleg have now is {i, o}.
Igor replaces the third question mark with 'o'. The company name becomes ?io. The set of letters Igor have now is {i, m}.
Finally, Oleg replaces the first question mark with 'o'. The company name becomes oio. The set of letters Oleg have now is {i}.
In the end, the company name is oio.
Oleg wants the company name to be as lexicographically small as possible while Igor wants the company name to be as lexicographically large as possible. What will be the company name if Oleg and Igor always play optimally?
A string s = s_1s_2...s_{m} is called lexicographically smaller than a string t = t_1t_2...t_{m} (where s β t) if s_{i} < t_{i} where i is the smallest index such that s_{i} β t_{i}. (so s_{j} = t_{j} for all j < i)
-----Input-----
The first line of input contains a string s of length n (1 β€ n β€ 3Β·10^5). All characters of the string are lowercase English letters. This string denotes the set of letters Oleg has initially.
The second line of input contains a string t of length n. All characters of the string are lowercase English letters. This string denotes the set of letters Igor has initially.
-----Output-----
The output should contain a string of n lowercase English letters, denoting the company name if Oleg and Igor plays optimally.
-----Examples-----
Input
tinkoff
zscoder
Output
fzfsirk
Input
xxxxxx
xxxxxx
Output
xxxxxx
Input
ioi
imo
Output
ioi
-----Note-----
One way to play optimally in the first sample is as follows : Initially, the company name is ???????. Oleg replaces the first question mark with 'f'. The company name becomes f??????. Igor replaces the second question mark with 'z'. The company name becomes fz?????. Oleg replaces the third question mark with 'f'. The company name becomes fzf????. Igor replaces the fourth question mark with 's'. The company name becomes fzfs???. Oleg replaces the fifth question mark with 'i'. The company name becomes fzfsi??. Igor replaces the sixth question mark with 'r'. The company name becomes fzfsir?. Oleg replaces the seventh question mark with 'k'. The company name becomes fzfsirk.
For the second sample, no matter how they play, the company name will always be xxxxxx.
|
a = sorted(input())
b = sorted(input(), reverse=True)
n = len(a)
a = "".join(a[: (n + 1) // 2])
b = "".join(b[: n // 2])
name = [""] * (len(a) + len(b))
ia = ib = ic = 0
ja = len(a) - 1
jb = len(b) - 1
jc = len(name) - 1
turn = 1
while ic <= jc:
if turn == 1:
if ib > jb:
name[ic] = a[ia]
ic += 1
elif a[ia] < b[ib]:
name[ic] = a[ia]
ia += 1
ic += 1
else:
name[jc] = a[ja]
ja -= 1
jc -= 1
elif ia > ja:
name[ic] = b[ib]
ic += 1
elif b[ib] > a[ia]:
name[ic] = b[ib]
ib += 1
ic += 1
else:
name[jc] = b[jb]
jb -= 1
jc -= 1
turn = 3 - turn
print("".join(name))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL STRING VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL STRING VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP LIST STRING BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
Oleg the client and Igor the analyst are good friends. However, sometimes they argue over little things. Recently, they started a new company, but they are having trouble finding a name for the company.
To settle this problem, they've decided to play a game. The company name will consist of n letters. Oleg and Igor each have a set of n letters (which might contain multiple copies of the same letter, the sets can be different). Initially, the company name is denoted by n question marks. Oleg and Igor takes turns to play the game, Oleg moves first. In each turn, a player can choose one of the letters c in his set and replace any of the question marks with c. Then, a copy of the letter c is removed from his set. The game ends when all the question marks has been replaced by some letter.
For example, suppose Oleg has the set of letters {i, o, i} and Igor has the set of letters {i, m, o}. One possible game is as follows :
Initially, the company name is ???.
Oleg replaces the second question mark with 'i'. The company name becomes ?i?. The set of letters Oleg have now is {i, o}.
Igor replaces the third question mark with 'o'. The company name becomes ?io. The set of letters Igor have now is {i, m}.
Finally, Oleg replaces the first question mark with 'o'. The company name becomes oio. The set of letters Oleg have now is {i}.
In the end, the company name is oio.
Oleg wants the company name to be as lexicographically small as possible while Igor wants the company name to be as lexicographically large as possible. What will be the company name if Oleg and Igor always play optimally?
A string s = s_1s_2...s_{m} is called lexicographically smaller than a string t = t_1t_2...t_{m} (where s β t) if s_{i} < t_{i} where i is the smallest index such that s_{i} β t_{i}. (so s_{j} = t_{j} for all j < i)
-----Input-----
The first line of input contains a string s of length n (1 β€ n β€ 3Β·10^5). All characters of the string are lowercase English letters. This string denotes the set of letters Oleg has initially.
The second line of input contains a string t of length n. All characters of the string are lowercase English letters. This string denotes the set of letters Igor has initially.
-----Output-----
The output should contain a string of n lowercase English letters, denoting the company name if Oleg and Igor plays optimally.
-----Examples-----
Input
tinkoff
zscoder
Output
fzfsirk
Input
xxxxxx
xxxxxx
Output
xxxxxx
Input
ioi
imo
Output
ioi
-----Note-----
One way to play optimally in the first sample is as follows : Initially, the company name is ???????. Oleg replaces the first question mark with 'f'. The company name becomes f??????. Igor replaces the second question mark with 'z'. The company name becomes fz?????. Oleg replaces the third question mark with 'f'. The company name becomes fzf????. Igor replaces the fourth question mark with 's'. The company name becomes fzfs???. Oleg replaces the fifth question mark with 'i'. The company name becomes fzfsi??. Igor replaces the sixth question mark with 'r'. The company name becomes fzfsir?. Oleg replaces the seventh question mark with 'k'. The company name becomes fzfsirk.
For the second sample, no matter how they play, the company name will always be xxxxxx.
|
s = list(map(str, input()))
c = list(map(str, input()))
n = len(s)
s.sort()
c.sort(reverse=True)
s = s[: (n + 1) // 2]
c = c[: n // 2]
l_s = len(s)
l_c = len(c)
begin_s = 0
begin_c = 0
end_s = l_s - 1
end_c = l_c - 1
ans1 = []
ans2 = []
for i in range(n - 1):
if i % 2 == 0:
if s[begin_s] >= c[begin_c]:
ans2.append(s[end_s])
end_s -= 1
else:
ans1.append(s[begin_s])
begin_s += 1
elif c[begin_c] <= s[begin_s]:
ans2.append(c[end_c])
end_c -= 1
else:
ans1.append(c[begin_c])
begin_c += 1
if n % 2:
ans1.append(s[begin_s])
else:
ans1.append(c[begin_c])
print(*(ans1 + list(reversed(ans2))), sep="")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR FUNC_CALL VAR FUNC_CALL VAR VAR STRING
|
There are $n$ quests. If you complete the $i$-th quest, you will gain $a_i$ coins. You can only complete at most one quest per day. However, once you complete a quest, you cannot do the same quest again for $k$ days. (For example, if $k=2$ and you do quest $1$ on day $1$, then you cannot do it on day $2$ or $3$, but you can do it again on day $4$.)
You are given two integers $c$ and $d$. Find the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days. If no such $k$ exists, output Impossible. If $k$ can be arbitrarily large, output Infinity.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 10^4$) β the number of test cases. The description of the test cases follows.
The first line of each test case contains three integers $n,c,d$ ($2 \leq n \leq 2\cdot10^5$; $1 \leq c \leq 10^{16}$; $1 \leq d \leq 2\cdot10^5$) β the number of quests, the number of coins you need, and the number of days.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^9$) β the rewards for the quests.
The sum of $n$ over all test cases does not exceed $2\cdot10^5$, and the sum of $d$ over all test cases does not exceed $2\cdot10^5$.
-----Output-----
For each test case, output one of the following.
If no such $k$ exists, output Impossible.
If $k$ can be arbitrarily large, output Infinity.
Otherwise, output a single integer β the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days.
Please note, the checker is case-sensitive, and you should output strings exactly as they are given.
-----Examples-----
Input
6
2 5 4
1 2
2 20 10
100 10
3 100 3
7 2 6
4 20 3
4 5 6 7
4 100000000000 2022
8217734 927368 26389746 627896974
2 20 4
5 1
Output
2
Infinity
Impossible
1
12
0
-----Note-----
In the first test case, one way to earn $5$ coins over $4$ days with $k=2$ is as follows:
Day 1: do quest 2, and earn $2$ coins.
Day 2: do quest 1, and earn $1$ coin.
Day 3: do nothing.
Day 4: do quest 2, and earn $2$ coins.
In total, we earned $2+1+2=5$ coins.
In the second test case, we can make over $20$ coins on the first day itself by doing the first quest to earn $100$ coins, so the value of $k$ can be arbitrarily large, since we never need to do another quest.
In the third test case, no matter what we do, we can't earn $100$ coins over $3$ days.
|
def bina(l, r, c, d, ss, n):
m = (l + r + 1) // 2
if l == r:
return l
y = d // (m + 1)
otv = ss[min(n - 1, m)] * y
if (m + 1) * y < d:
otv += ss[min(n, d - y * (m + 1)) - 1]
if otv >= c:
return bina(m, r, c, d, ss, n)
else:
return bina(l, m - 1, c, d, ss, n)
t = int(input())
for test in range(t):
n, c, d = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
x = sum(a[: min(n, d)])
if x >= c:
print("Infinity")
elif a[0] * d < c:
print("Impossible")
else:
ss = [0] * n
ss[0] = a[0]
for i in range(1, n):
ss[i] = ss[i - 1] + a[i]
print(bina(0, d, c, d, ss, n))
|
FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR VAR RETURN VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR IF BIN_OP BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR
|
There are $n$ quests. If you complete the $i$-th quest, you will gain $a_i$ coins. You can only complete at most one quest per day. However, once you complete a quest, you cannot do the same quest again for $k$ days. (For example, if $k=2$ and you do quest $1$ on day $1$, then you cannot do it on day $2$ or $3$, but you can do it again on day $4$.)
You are given two integers $c$ and $d$. Find the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days. If no such $k$ exists, output Impossible. If $k$ can be arbitrarily large, output Infinity.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 10^4$) β the number of test cases. The description of the test cases follows.
The first line of each test case contains three integers $n,c,d$ ($2 \leq n \leq 2\cdot10^5$; $1 \leq c \leq 10^{16}$; $1 \leq d \leq 2\cdot10^5$) β the number of quests, the number of coins you need, and the number of days.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^9$) β the rewards for the quests.
The sum of $n$ over all test cases does not exceed $2\cdot10^5$, and the sum of $d$ over all test cases does not exceed $2\cdot10^5$.
-----Output-----
For each test case, output one of the following.
If no such $k$ exists, output Impossible.
If $k$ can be arbitrarily large, output Infinity.
Otherwise, output a single integer β the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days.
Please note, the checker is case-sensitive, and you should output strings exactly as they are given.
-----Examples-----
Input
6
2 5 4
1 2
2 20 10
100 10
3 100 3
7 2 6
4 20 3
4 5 6 7
4 100000000000 2022
8217734 927368 26389746 627896974
2 20 4
5 1
Output
2
Infinity
Impossible
1
12
0
-----Note-----
In the first test case, one way to earn $5$ coins over $4$ days with $k=2$ is as follows:
Day 1: do quest 2, and earn $2$ coins.
Day 2: do quest 1, and earn $1$ coin.
Day 3: do nothing.
Day 4: do quest 2, and earn $2$ coins.
In total, we earned $2+1+2=5$ coins.
In the second test case, we can make over $20$ coins on the first day itself by doing the first quest to earn $100$ coins, so the value of $k$ can be arbitrarily large, since we never need to do another quest.
In the third test case, no matter what we do, we can't earn $100$ coins over $3$ days.
|
import sys
input = sys.stdin.readline
def solve():
N, C, D = list(map(int, input().split()))
A = list(map(int, input().split()))
A.sort()
i = N - 1
temp = 0
for _ in range(min(D, N)):
temp += A[i]
i -= 1
if temp >= C:
print("Infinity")
return
if D * A[-1] < C:
print("Impossible")
return
A.reverse()
ans = 0
l, r = 0, D - 1
while l <= r:
mid = (l + r) // 2
k = mid + 1
t = 0
j = 0
while j < D:
if j % k < N:
t += A[j % k]
j += 1
else:
j += k - j % k
if t >= C:
ans = mid
l = mid + 1
else:
r = mid - 1
print(ans)
for _ in range(int(input())):
solve()
|
IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING RETURN IF BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
There are $n$ quests. If you complete the $i$-th quest, you will gain $a_i$ coins. You can only complete at most one quest per day. However, once you complete a quest, you cannot do the same quest again for $k$ days. (For example, if $k=2$ and you do quest $1$ on day $1$, then you cannot do it on day $2$ or $3$, but you can do it again on day $4$.)
You are given two integers $c$ and $d$. Find the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days. If no such $k$ exists, output Impossible. If $k$ can be arbitrarily large, output Infinity.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 10^4$) β the number of test cases. The description of the test cases follows.
The first line of each test case contains three integers $n,c,d$ ($2 \leq n \leq 2\cdot10^5$; $1 \leq c \leq 10^{16}$; $1 \leq d \leq 2\cdot10^5$) β the number of quests, the number of coins you need, and the number of days.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^9$) β the rewards for the quests.
The sum of $n$ over all test cases does not exceed $2\cdot10^5$, and the sum of $d$ over all test cases does not exceed $2\cdot10^5$.
-----Output-----
For each test case, output one of the following.
If no such $k$ exists, output Impossible.
If $k$ can be arbitrarily large, output Infinity.
Otherwise, output a single integer β the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days.
Please note, the checker is case-sensitive, and you should output strings exactly as they are given.
-----Examples-----
Input
6
2 5 4
1 2
2 20 10
100 10
3 100 3
7 2 6
4 20 3
4 5 6 7
4 100000000000 2022
8217734 927368 26389746 627896974
2 20 4
5 1
Output
2
Infinity
Impossible
1
12
0
-----Note-----
In the first test case, one way to earn $5$ coins over $4$ days with $k=2$ is as follows:
Day 1: do quest 2, and earn $2$ coins.
Day 2: do quest 1, and earn $1$ coin.
Day 3: do nothing.
Day 4: do quest 2, and earn $2$ coins.
In total, we earned $2+1+2=5$ coins.
In the second test case, we can make over $20$ coins on the first day itself by doing the first quest to earn $100$ coins, so the value of $k$ can be arbitrarily large, since we never need to do another quest.
In the third test case, no matter what we do, we can't earn $100$ coins over $3$ days.
|
def compute_max(numbers, k, d, n):
sum = 0
for i in range(d):
if i % (k + 1) < n:
sum += numbers[i % (k + 1)]
return sum
t = int(input())
while t > 0:
ncd = [int(x) for x in input().split()]
n = ncd[0]
c = ncd[1]
d = ncd[2]
list_of_numbers = [int(x) for x in input().split()]
list_of_numbers.sort(reverse=True)
show_infinity = sum(list_of_numbers[: min(d, n)])
if show_infinity >= c:
print("Infinity")
elif list_of_numbers[0] * d < c:
print("Impossible")
else:
left = 0
right = d - 1
ans = 0
while left <= right:
middle = int((left + right) / 2)
max_coins = compute_max(list_of_numbers, middle, d, n)
if max_coins >= c:
ans = middle
left = middle + 1
if max_coins < c:
right = middle - 1
print(ans)
t = t - 1
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER
|
There are $n$ quests. If you complete the $i$-th quest, you will gain $a_i$ coins. You can only complete at most one quest per day. However, once you complete a quest, you cannot do the same quest again for $k$ days. (For example, if $k=2$ and you do quest $1$ on day $1$, then you cannot do it on day $2$ or $3$, but you can do it again on day $4$.)
You are given two integers $c$ and $d$. Find the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days. If no such $k$ exists, output Impossible. If $k$ can be arbitrarily large, output Infinity.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 10^4$) β the number of test cases. The description of the test cases follows.
The first line of each test case contains three integers $n,c,d$ ($2 \leq n \leq 2\cdot10^5$; $1 \leq c \leq 10^{16}$; $1 \leq d \leq 2\cdot10^5$) β the number of quests, the number of coins you need, and the number of days.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^9$) β the rewards for the quests.
The sum of $n$ over all test cases does not exceed $2\cdot10^5$, and the sum of $d$ over all test cases does not exceed $2\cdot10^5$.
-----Output-----
For each test case, output one of the following.
If no such $k$ exists, output Impossible.
If $k$ can be arbitrarily large, output Infinity.
Otherwise, output a single integer β the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days.
Please note, the checker is case-sensitive, and you should output strings exactly as they are given.
-----Examples-----
Input
6
2 5 4
1 2
2 20 10
100 10
3 100 3
7 2 6
4 20 3
4 5 6 7
4 100000000000 2022
8217734 927368 26389746 627896974
2 20 4
5 1
Output
2
Infinity
Impossible
1
12
0
-----Note-----
In the first test case, one way to earn $5$ coins over $4$ days with $k=2$ is as follows:
Day 1: do quest 2, and earn $2$ coins.
Day 2: do quest 1, and earn $1$ coin.
Day 3: do nothing.
Day 4: do quest 2, and earn $2$ coins.
In total, we earned $2+1+2=5$ coins.
In the second test case, we can make over $20$ coins on the first day itself by doing the first quest to earn $100$ coins, so the value of $k$ can be arbitrarily large, since we never need to do another quest.
In the third test case, no matter what we do, we can't earn $100$ coins over $3$ days.
|
t = int(input())
while t > 0:
n, c, d = list(map(int, input().split(" ")))
a = list(map(int, input().split(" ")))
a.sort(reverse=True)
left, right = 0, d + 2
while left < right:
mid = left + (right - left + 1) // 2
total = 0
current = 0
for i in range(d):
if i % mid < n:
total += a[i % mid]
if total >= c:
left = mid
else:
right = mid - 1
if left == d + 2:
print("Infinity")
elif left == 0:
print("Impossible")
else:
print(left - 1)
t -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER
|
There are $n$ quests. If you complete the $i$-th quest, you will gain $a_i$ coins. You can only complete at most one quest per day. However, once you complete a quest, you cannot do the same quest again for $k$ days. (For example, if $k=2$ and you do quest $1$ on day $1$, then you cannot do it on day $2$ or $3$, but you can do it again on day $4$.)
You are given two integers $c$ and $d$. Find the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days. If no such $k$ exists, output Impossible. If $k$ can be arbitrarily large, output Infinity.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 10^4$) β the number of test cases. The description of the test cases follows.
The first line of each test case contains three integers $n,c,d$ ($2 \leq n \leq 2\cdot10^5$; $1 \leq c \leq 10^{16}$; $1 \leq d \leq 2\cdot10^5$) β the number of quests, the number of coins you need, and the number of days.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^9$) β the rewards for the quests.
The sum of $n$ over all test cases does not exceed $2\cdot10^5$, and the sum of $d$ over all test cases does not exceed $2\cdot10^5$.
-----Output-----
For each test case, output one of the following.
If no such $k$ exists, output Impossible.
If $k$ can be arbitrarily large, output Infinity.
Otherwise, output a single integer β the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days.
Please note, the checker is case-sensitive, and you should output strings exactly as they are given.
-----Examples-----
Input
6
2 5 4
1 2
2 20 10
100 10
3 100 3
7 2 6
4 20 3
4 5 6 7
4 100000000000 2022
8217734 927368 26389746 627896974
2 20 4
5 1
Output
2
Infinity
Impossible
1
12
0
-----Note-----
In the first test case, one way to earn $5$ coins over $4$ days with $k=2$ is as follows:
Day 1: do quest 2, and earn $2$ coins.
Day 2: do quest 1, and earn $1$ coin.
Day 3: do nothing.
Day 4: do quest 2, and earn $2$ coins.
In total, we earned $2+1+2=5$ coins.
In the second test case, we can make over $20$ coins on the first day itself by doing the first quest to earn $100$ coins, so the value of $k$ can be arbitrarily large, since we never need to do another quest.
In the third test case, no matter what we do, we can't earn $100$ coins over $3$ days.
|
def calc(v, arr):
v += 1
tmp1 = d // v
tmp2 = d % v
t = sum(arr[:v])
tmp_out = tmp1 * t + sum(arr[:tmp2])
if tmp_out >= c:
return tmp_out
else:
return False
def binarySearch(low, high, out):
index = (high + low + 1) // 2
tmp_out = calc(index, arr_sort)
if high == low:
return out
if tmp_out:
out = max(out, index)
return binarySearch(index, high, out)
else:
return binarySearch(low, index - 1, out)
for _ in range(int(input())):
n, c, d = map(int, input().split())
arr = list(map(int, input().split()))
arr_sort = sorted(arr, reverse=True)
arr_sort_sum = sum(arr_sort)
arr_to_d = sum(arr_sort[:d])
m = max(arr)
out = 0
if d * m < c:
print("Impossible")
elif arr_to_d >= c:
print("Infinity")
else:
print(binarySearch(0, d, out))
|
FUNC_DEF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR RETURN VAR RETURN NUMBER FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR RETURN VAR IF VAR ASSIGN VAR FUNC_CALL VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR VAR
|
There are $n$ quests. If you complete the $i$-th quest, you will gain $a_i$ coins. You can only complete at most one quest per day. However, once you complete a quest, you cannot do the same quest again for $k$ days. (For example, if $k=2$ and you do quest $1$ on day $1$, then you cannot do it on day $2$ or $3$, but you can do it again on day $4$.)
You are given two integers $c$ and $d$. Find the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days. If no such $k$ exists, output Impossible. If $k$ can be arbitrarily large, output Infinity.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 10^4$) β the number of test cases. The description of the test cases follows.
The first line of each test case contains three integers $n,c,d$ ($2 \leq n \leq 2\cdot10^5$; $1 \leq c \leq 10^{16}$; $1 \leq d \leq 2\cdot10^5$) β the number of quests, the number of coins you need, and the number of days.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^9$) β the rewards for the quests.
The sum of $n$ over all test cases does not exceed $2\cdot10^5$, and the sum of $d$ over all test cases does not exceed $2\cdot10^5$.
-----Output-----
For each test case, output one of the following.
If no such $k$ exists, output Impossible.
If $k$ can be arbitrarily large, output Infinity.
Otherwise, output a single integer β the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days.
Please note, the checker is case-sensitive, and you should output strings exactly as they are given.
-----Examples-----
Input
6
2 5 4
1 2
2 20 10
100 10
3 100 3
7 2 6
4 20 3
4 5 6 7
4 100000000000 2022
8217734 927368 26389746 627896974
2 20 4
5 1
Output
2
Infinity
Impossible
1
12
0
-----Note-----
In the first test case, one way to earn $5$ coins over $4$ days with $k=2$ is as follows:
Day 1: do quest 2, and earn $2$ coins.
Day 2: do quest 1, and earn $1$ coin.
Day 3: do nothing.
Day 4: do quest 2, and earn $2$ coins.
In total, we earned $2+1+2=5$ coins.
In the second test case, we can make over $20$ coins on the first day itself by doing the first quest to earn $100$ coins, so the value of $k$ can be arbitrarily large, since we never need to do another quest.
In the third test case, no matter what we do, we can't earn $100$ coins over $3$ days.
|
t = int(input())
for _ in range(t):
n, c, d = map(int, input().split())
q = list(map(int, input().split()))
q.sort(reverse=True)
def check_k(k):
blocks = d // (k + 1)
block_sum = sum(q[: min(k + 1, n)])
pre_mon = blocks * block_sum
left_over = d - (k + 1) * blocks
for i in range(min(left_over, n)):
pre_mon += q[i]
return pre_mon >= c
l = 0
r = d
if not check_k(0):
print("Impossible")
continue
if check_k(d):
print("Infinity")
continue
while l < r - 1:
m = (l + r) // 2
afn = check_k(m)
if afn:
l = m
else:
r = m
print(l)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR RETURN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR IF FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR STRING IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
There are $n$ quests. If you complete the $i$-th quest, you will gain $a_i$ coins. You can only complete at most one quest per day. However, once you complete a quest, you cannot do the same quest again for $k$ days. (For example, if $k=2$ and you do quest $1$ on day $1$, then you cannot do it on day $2$ or $3$, but you can do it again on day $4$.)
You are given two integers $c$ and $d$. Find the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days. If no such $k$ exists, output Impossible. If $k$ can be arbitrarily large, output Infinity.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 10^4$) β the number of test cases. The description of the test cases follows.
The first line of each test case contains three integers $n,c,d$ ($2 \leq n \leq 2\cdot10^5$; $1 \leq c \leq 10^{16}$; $1 \leq d \leq 2\cdot10^5$) β the number of quests, the number of coins you need, and the number of days.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^9$) β the rewards for the quests.
The sum of $n$ over all test cases does not exceed $2\cdot10^5$, and the sum of $d$ over all test cases does not exceed $2\cdot10^5$.
-----Output-----
For each test case, output one of the following.
If no such $k$ exists, output Impossible.
If $k$ can be arbitrarily large, output Infinity.
Otherwise, output a single integer β the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days.
Please note, the checker is case-sensitive, and you should output strings exactly as they are given.
-----Examples-----
Input
6
2 5 4
1 2
2 20 10
100 10
3 100 3
7 2 6
4 20 3
4 5 6 7
4 100000000000 2022
8217734 927368 26389746 627896974
2 20 4
5 1
Output
2
Infinity
Impossible
1
12
0
-----Note-----
In the first test case, one way to earn $5$ coins over $4$ days with $k=2$ is as follows:
Day 1: do quest 2, and earn $2$ coins.
Day 2: do quest 1, and earn $1$ coin.
Day 3: do nothing.
Day 4: do quest 2, and earn $2$ coins.
In total, we earned $2+1+2=5$ coins.
In the second test case, we can make over $20$ coins on the first day itself by doing the first quest to earn $100$ coins, so the value of $k$ can be arbitrarily large, since we never need to do another quest.
In the third test case, no matter what we do, we can't earn $100$ coins over $3$ days.
|
def bin():
l = 0
r = 1
while isok(r):
r *= 2
while r - l > 1:
m = (l + r) // 2
if isok(m):
l = m
else:
r = m
return l
def isok(n):
pz = d // n
npz = d % n
sum = pz * p[min(n, len(s))] + p[min(npz, len(s))]
return sum >= c
for qwer in range(int(input())):
n, c, d = map(int, input().split())
s = list(map(int, input().split()))
s.sort(reverse=True)
p = [0]
for i in s:
p.append(p[-1] + i)
if s[0] * d < c:
print("Impossible")
elif p[min(len(s), d)] >= c:
print("Infinity")
else:
print(bin() - 1)
|
FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR RETURN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING IF VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR NUMBER
|
There are $n$ quests. If you complete the $i$-th quest, you will gain $a_i$ coins. You can only complete at most one quest per day. However, once you complete a quest, you cannot do the same quest again for $k$ days. (For example, if $k=2$ and you do quest $1$ on day $1$, then you cannot do it on day $2$ or $3$, but you can do it again on day $4$.)
You are given two integers $c$ and $d$. Find the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days. If no such $k$ exists, output Impossible. If $k$ can be arbitrarily large, output Infinity.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 10^4$) β the number of test cases. The description of the test cases follows.
The first line of each test case contains three integers $n,c,d$ ($2 \leq n \leq 2\cdot10^5$; $1 \leq c \leq 10^{16}$; $1 \leq d \leq 2\cdot10^5$) β the number of quests, the number of coins you need, and the number of days.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^9$) β the rewards for the quests.
The sum of $n$ over all test cases does not exceed $2\cdot10^5$, and the sum of $d$ over all test cases does not exceed $2\cdot10^5$.
-----Output-----
For each test case, output one of the following.
If no such $k$ exists, output Impossible.
If $k$ can be arbitrarily large, output Infinity.
Otherwise, output a single integer β the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days.
Please note, the checker is case-sensitive, and you should output strings exactly as they are given.
-----Examples-----
Input
6
2 5 4
1 2
2 20 10
100 10
3 100 3
7 2 6
4 20 3
4 5 6 7
4 100000000000 2022
8217734 927368 26389746 627896974
2 20 4
5 1
Output
2
Infinity
Impossible
1
12
0
-----Note-----
In the first test case, one way to earn $5$ coins over $4$ days with $k=2$ is as follows:
Day 1: do quest 2, and earn $2$ coins.
Day 2: do quest 1, and earn $1$ coin.
Day 3: do nothing.
Day 4: do quest 2, and earn $2$ coins.
In total, we earned $2+1+2=5$ coins.
In the second test case, we can make over $20$ coins on the first day itself by doing the first quest to earn $100$ coins, so the value of $k$ can be arbitrarily large, since we never need to do another quest.
In the third test case, no matter what we do, we can't earn $100$ coins over $3$ days.
|
for _ in range(int(input())):
a, b1, c = map(int, input().split())
ls = sorted(list(map(int, input().split())), reverse=True)
b = [0] * (a + 1)
for i in range(1, a + 1):
b[i] = b[i - 1] + ls[i - 1]
if b[min(a, c)] >= b1:
print("Infinity")
continue
flag = -1
for i in range(c - 1):
t = b[min(i + 1, a)] * (c // (i + 1)) + b[min(c % (i + 1), a)]
if b1 <= t:
flag = i
else:
break
if flag == -1:
print("Impossible")
else:
print(flag)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
|
There are $n$ quests. If you complete the $i$-th quest, you will gain $a_i$ coins. You can only complete at most one quest per day. However, once you complete a quest, you cannot do the same quest again for $k$ days. (For example, if $k=2$ and you do quest $1$ on day $1$, then you cannot do it on day $2$ or $3$, but you can do it again on day $4$.)
You are given two integers $c$ and $d$. Find the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days. If no such $k$ exists, output Impossible. If $k$ can be arbitrarily large, output Infinity.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 10^4$) β the number of test cases. The description of the test cases follows.
The first line of each test case contains three integers $n,c,d$ ($2 \leq n \leq 2\cdot10^5$; $1 \leq c \leq 10^{16}$; $1 \leq d \leq 2\cdot10^5$) β the number of quests, the number of coins you need, and the number of days.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^9$) β the rewards for the quests.
The sum of $n$ over all test cases does not exceed $2\cdot10^5$, and the sum of $d$ over all test cases does not exceed $2\cdot10^5$.
-----Output-----
For each test case, output one of the following.
If no such $k$ exists, output Impossible.
If $k$ can be arbitrarily large, output Infinity.
Otherwise, output a single integer β the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days.
Please note, the checker is case-sensitive, and you should output strings exactly as they are given.
-----Examples-----
Input
6
2 5 4
1 2
2 20 10
100 10
3 100 3
7 2 6
4 20 3
4 5 6 7
4 100000000000 2022
8217734 927368 26389746 627896974
2 20 4
5 1
Output
2
Infinity
Impossible
1
12
0
-----Note-----
In the first test case, one way to earn $5$ coins over $4$ days with $k=2$ is as follows:
Day 1: do quest 2, and earn $2$ coins.
Day 2: do quest 1, and earn $1$ coin.
Day 3: do nothing.
Day 4: do quest 2, and earn $2$ coins.
In total, we earned $2+1+2=5$ coins.
In the second test case, we can make over $20$ coins on the first day itself by doing the first quest to earn $100$ coins, so the value of $k$ can be arbitrarily large, since we never need to do another quest.
In the third test case, no matter what we do, we can't earn $100$ coins over $3$ days.
|
inf = 2**60
for tcase in range(int(input())):
n, c, d = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
a = [0] + a
for i in range(n):
a[i + 1] += a[i]
l, r = -1, inf
while r - l > 1:
k = (l + r) // 2
d1, d2 = divmod(d, k + 1)
if c <= a[min(n, k + 1)] * d1 + a[min(n, d2)]:
l = k
else:
r = k
if l > inf // 3:
print("Infinity")
elif l < 0:
print("Impossible")
else:
print(l)
|
ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER IF VAR BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
|
There are $n$ quests. If you complete the $i$-th quest, you will gain $a_i$ coins. You can only complete at most one quest per day. However, once you complete a quest, you cannot do the same quest again for $k$ days. (For example, if $k=2$ and you do quest $1$ on day $1$, then you cannot do it on day $2$ or $3$, but you can do it again on day $4$.)
You are given two integers $c$ and $d$. Find the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days. If no such $k$ exists, output Impossible. If $k$ can be arbitrarily large, output Infinity.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 10^4$) β the number of test cases. The description of the test cases follows.
The first line of each test case contains three integers $n,c,d$ ($2 \leq n \leq 2\cdot10^5$; $1 \leq c \leq 10^{16}$; $1 \leq d \leq 2\cdot10^5$) β the number of quests, the number of coins you need, and the number of days.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^9$) β the rewards for the quests.
The sum of $n$ over all test cases does not exceed $2\cdot10^5$, and the sum of $d$ over all test cases does not exceed $2\cdot10^5$.
-----Output-----
For each test case, output one of the following.
If no such $k$ exists, output Impossible.
If $k$ can be arbitrarily large, output Infinity.
Otherwise, output a single integer β the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days.
Please note, the checker is case-sensitive, and you should output strings exactly as they are given.
-----Examples-----
Input
6
2 5 4
1 2
2 20 10
100 10
3 100 3
7 2 6
4 20 3
4 5 6 7
4 100000000000 2022
8217734 927368 26389746 627896974
2 20 4
5 1
Output
2
Infinity
Impossible
1
12
0
-----Note-----
In the first test case, one way to earn $5$ coins over $4$ days with $k=2$ is as follows:
Day 1: do quest 2, and earn $2$ coins.
Day 2: do quest 1, and earn $1$ coin.
Day 3: do nothing.
Day 4: do quest 2, and earn $2$ coins.
In total, we earned $2+1+2=5$ coins.
In the second test case, we can make over $20$ coins on the first day itself by doing the first quest to earn $100$ coins, so the value of $k$ can be arbitrarily large, since we never need to do another quest.
In the third test case, no matter what we do, we can't earn $100$ coins over $3$ days.
|
t = int(input())
for _ in range(t):
a = [int(i) for i in input().split()]
n = a[0]
c = a[1]
d = a[2]
a = [int(i) for i in input().split()]
a.sort()
a = a[::-1]
if sum(a[: min(n, d)]) >= c:
print("Infinity")
continue
if d * a[0] < c:
print("Impossible")
continue
k1 = 0
l = 0
r = d
while r - l > 1:
k = (r + l) // 2
if c <= sum(a[: min(k + 1, n)]) * (d // (k + 1)) + sum(
a[: min(n, d % (k + 1))]
):
l = k
k1 = max(k1, k)
else:
r = k
print(k1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
There are $n$ quests. If you complete the $i$-th quest, you will gain $a_i$ coins. You can only complete at most one quest per day. However, once you complete a quest, you cannot do the same quest again for $k$ days. (For example, if $k=2$ and you do quest $1$ on day $1$, then you cannot do it on day $2$ or $3$, but you can do it again on day $4$.)
You are given two integers $c$ and $d$. Find the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days. If no such $k$ exists, output Impossible. If $k$ can be arbitrarily large, output Infinity.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 10^4$) β the number of test cases. The description of the test cases follows.
The first line of each test case contains three integers $n,c,d$ ($2 \leq n \leq 2\cdot10^5$; $1 \leq c \leq 10^{16}$; $1 \leq d \leq 2\cdot10^5$) β the number of quests, the number of coins you need, and the number of days.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^9$) β the rewards for the quests.
The sum of $n$ over all test cases does not exceed $2\cdot10^5$, and the sum of $d$ over all test cases does not exceed $2\cdot10^5$.
-----Output-----
For each test case, output one of the following.
If no such $k$ exists, output Impossible.
If $k$ can be arbitrarily large, output Infinity.
Otherwise, output a single integer β the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days.
Please note, the checker is case-sensitive, and you should output strings exactly as they are given.
-----Examples-----
Input
6
2 5 4
1 2
2 20 10
100 10
3 100 3
7 2 6
4 20 3
4 5 6 7
4 100000000000 2022
8217734 927368 26389746 627896974
2 20 4
5 1
Output
2
Infinity
Impossible
1
12
0
-----Note-----
In the first test case, one way to earn $5$ coins over $4$ days with $k=2$ is as follows:
Day 1: do quest 2, and earn $2$ coins.
Day 2: do quest 1, and earn $1$ coin.
Day 3: do nothing.
Day 4: do quest 2, and earn $2$ coins.
In total, we earned $2+1+2=5$ coins.
In the second test case, we can make over $20$ coins on the first day itself by doing the first quest to earn $100$ coins, so the value of $k$ can be arbitrarily large, since we never need to do another quest.
In the third test case, no matter what we do, we can't earn $100$ coins over $3$ days.
|
def calc(pre, k, d):
recur = 0
if k >= len(pre):
recur = pre[-1]
else:
recur = pre[k - 1]
cycles = d // k
leftover = d % k
add = 0
if leftover > len(pre):
add = pre[-1]
elif leftover == 0:
add = 0
else:
add = pre[leftover - 1]
return recur * cycles + add
q = int(input())
for o in range(q):
n, c, d = map(int, input().strip().split())
a = list(map(int, input().strip().split()))
a.sort()
a.reverse()
pre = [(0) for i in range(n)]
cur = 0
for i in range(len(a)):
cur += a[i]
pre[i] = cur
l = 1
r = d
while r - l > 1:
m = (r + l) // 2
if calc(pre, m, d) >= c:
l = m
else:
r = m
if calc(pre, r, d) >= c:
if r == d:
print("Infinity")
else:
print(r - 1)
elif calc(pre, 1, d) < c:
print("Impossible")
else:
print(l - 1)
|
FUNC_DEF ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
There are $n$ quests. If you complete the $i$-th quest, you will gain $a_i$ coins. You can only complete at most one quest per day. However, once you complete a quest, you cannot do the same quest again for $k$ days. (For example, if $k=2$ and you do quest $1$ on day $1$, then you cannot do it on day $2$ or $3$, but you can do it again on day $4$.)
You are given two integers $c$ and $d$. Find the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days. If no such $k$ exists, output Impossible. If $k$ can be arbitrarily large, output Infinity.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 10^4$) β the number of test cases. The description of the test cases follows.
The first line of each test case contains three integers $n,c,d$ ($2 \leq n \leq 2\cdot10^5$; $1 \leq c \leq 10^{16}$; $1 \leq d \leq 2\cdot10^5$) β the number of quests, the number of coins you need, and the number of days.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^9$) β the rewards for the quests.
The sum of $n$ over all test cases does not exceed $2\cdot10^5$, and the sum of $d$ over all test cases does not exceed $2\cdot10^5$.
-----Output-----
For each test case, output one of the following.
If no such $k$ exists, output Impossible.
If $k$ can be arbitrarily large, output Infinity.
Otherwise, output a single integer β the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days.
Please note, the checker is case-sensitive, and you should output strings exactly as they are given.
-----Examples-----
Input
6
2 5 4
1 2
2 20 10
100 10
3 100 3
7 2 6
4 20 3
4 5 6 7
4 100000000000 2022
8217734 927368 26389746 627896974
2 20 4
5 1
Output
2
Infinity
Impossible
1
12
0
-----Note-----
In the first test case, one way to earn $5$ coins over $4$ days with $k=2$ is as follows:
Day 1: do quest 2, and earn $2$ coins.
Day 2: do quest 1, and earn $1$ coin.
Day 3: do nothing.
Day 4: do quest 2, and earn $2$ coins.
In total, we earned $2+1+2=5$ coins.
In the second test case, we can make over $20$ coins on the first day itself by doing the first quest to earn $100$ coins, so the value of $k$ can be arbitrarily large, since we never need to do another quest.
In the third test case, no matter what we do, we can't earn $100$ coins over $3$ days.
|
t = int(input())
for i in range(t):
n, c, d = [int(x) for x in input().split()]
L = [int(x) for x in input().split()]
L.sort(reverse=True)
l, r = 0, 10**15
while l < r:
m = (l + r + 1) // 2
if m == 0:
l = 0
break
if sum(L[: min(m, n)]) * (d // m) + sum(L[: min(d % m, n)]) >= c:
l = m
else:
r = m - 1
print(
l - 1 if l != 10**15 and l != 0 else "Infinity" if r == 10**15 else "Impossible"
)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR BIN_OP NUMBER NUMBER VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP NUMBER NUMBER STRING STRING
|
There are $n$ quests. If you complete the $i$-th quest, you will gain $a_i$ coins. You can only complete at most one quest per day. However, once you complete a quest, you cannot do the same quest again for $k$ days. (For example, if $k=2$ and you do quest $1$ on day $1$, then you cannot do it on day $2$ or $3$, but you can do it again on day $4$.)
You are given two integers $c$ and $d$. Find the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days. If no such $k$ exists, output Impossible. If $k$ can be arbitrarily large, output Infinity.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 10^4$) β the number of test cases. The description of the test cases follows.
The first line of each test case contains three integers $n,c,d$ ($2 \leq n \leq 2\cdot10^5$; $1 \leq c \leq 10^{16}$; $1 \leq d \leq 2\cdot10^5$) β the number of quests, the number of coins you need, and the number of days.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^9$) β the rewards for the quests.
The sum of $n$ over all test cases does not exceed $2\cdot10^5$, and the sum of $d$ over all test cases does not exceed $2\cdot10^5$.
-----Output-----
For each test case, output one of the following.
If no such $k$ exists, output Impossible.
If $k$ can be arbitrarily large, output Infinity.
Otherwise, output a single integer β the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days.
Please note, the checker is case-sensitive, and you should output strings exactly as they are given.
-----Examples-----
Input
6
2 5 4
1 2
2 20 10
100 10
3 100 3
7 2 6
4 20 3
4 5 6 7
4 100000000000 2022
8217734 927368 26389746 627896974
2 20 4
5 1
Output
2
Infinity
Impossible
1
12
0
-----Note-----
In the first test case, one way to earn $5$ coins over $4$ days with $k=2$ is as follows:
Day 1: do quest 2, and earn $2$ coins.
Day 2: do quest 1, and earn $1$ coin.
Day 3: do nothing.
Day 4: do quest 2, and earn $2$ coins.
In total, we earned $2+1+2=5$ coins.
In the second test case, we can make over $20$ coins on the first day itself by doing the first quest to earn $100$ coins, so the value of $k$ can be arbitrarily large, since we never need to do another quest.
In the third test case, no matter what we do, we can't earn $100$ coins over $3$ days.
|
testcase = int(input())
for _ in range(testcase):
n, c, d = [int(num) for num in input().split()]
arr = [int(num) for num in input().split()]
arr.sort(reverse=True)
if sum(arr[:d]) >= c:
print("Infinity")
continue
if arr[0] * d < c:
print("Impossible")
continue
l = 0
r = d + 1
while l + 1 < r:
k = (l + r) // 2
s0 = sum(arr[d % (k + 1) : k + 1])
s1 = sum(arr[: d % (k + 1)])
ans = s0 * (d // (k + 1)) + s1 * ((d + k) // (k + 1))
if ans >= c:
l = k
else:
r = k
print(l)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
There are $n$ quests. If you complete the $i$-th quest, you will gain $a_i$ coins. You can only complete at most one quest per day. However, once you complete a quest, you cannot do the same quest again for $k$ days. (For example, if $k=2$ and you do quest $1$ on day $1$, then you cannot do it on day $2$ or $3$, but you can do it again on day $4$.)
You are given two integers $c$ and $d$. Find the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days. If no such $k$ exists, output Impossible. If $k$ can be arbitrarily large, output Infinity.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 10^4$) β the number of test cases. The description of the test cases follows.
The first line of each test case contains three integers $n,c,d$ ($2 \leq n \leq 2\cdot10^5$; $1 \leq c \leq 10^{16}$; $1 \leq d \leq 2\cdot10^5$) β the number of quests, the number of coins you need, and the number of days.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^9$) β the rewards for the quests.
The sum of $n$ over all test cases does not exceed $2\cdot10^5$, and the sum of $d$ over all test cases does not exceed $2\cdot10^5$.
-----Output-----
For each test case, output one of the following.
If no such $k$ exists, output Impossible.
If $k$ can be arbitrarily large, output Infinity.
Otherwise, output a single integer β the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days.
Please note, the checker is case-sensitive, and you should output strings exactly as they are given.
-----Examples-----
Input
6
2 5 4
1 2
2 20 10
100 10
3 100 3
7 2 6
4 20 3
4 5 6 7
4 100000000000 2022
8217734 927368 26389746 627896974
2 20 4
5 1
Output
2
Infinity
Impossible
1
12
0
-----Note-----
In the first test case, one way to earn $5$ coins over $4$ days with $k=2$ is as follows:
Day 1: do quest 2, and earn $2$ coins.
Day 2: do quest 1, and earn $1$ coin.
Day 3: do nothing.
Day 4: do quest 2, and earn $2$ coins.
In total, we earned $2+1+2=5$ coins.
In the second test case, we can make over $20$ coins on the first day itself by doing the first quest to earn $100$ coins, so the value of $k$ can be arbitrarily large, since we never need to do another quest.
In the third test case, no matter what we do, we can't earn $100$ coins over $3$ days.
|
for _ in range(int(input())):
n, c, d = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
zeros = []
if d > n:
zeros = [0] * (d - n)
arr = zeros + arr
m = len(arr)
ans = 0
arr1 = [0] * m
if arr[m - 1] * d < c:
ans = "Impossible"
elif sum(arr[m - d : m]) >= c:
ans = "Infinity"
else:
arr1[m - 1] = arr[m - 1]
for i in range(m - 2, -1, -1):
arr1[i] = arr1[i + 1] + arr[i]
for i in range(d, 0, -1):
que = d // i
rem = d % i
if rem > 0:
if que * arr1[m - i] + arr1[m - rem] >= c:
ans = i - 1
break
elif que * arr1[m - i] >= c:
ans = i - 1
break
print(ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST IF VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR STRING IF FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR STRING ASSIGN VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER IF BIN_OP BIN_OP VAR VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are $n$ quests. If you complete the $i$-th quest, you will gain $a_i$ coins. You can only complete at most one quest per day. However, once you complete a quest, you cannot do the same quest again for $k$ days. (For example, if $k=2$ and you do quest $1$ on day $1$, then you cannot do it on day $2$ or $3$, but you can do it again on day $4$.)
You are given two integers $c$ and $d$. Find the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days. If no such $k$ exists, output Impossible. If $k$ can be arbitrarily large, output Infinity.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 10^4$) β the number of test cases. The description of the test cases follows.
The first line of each test case contains three integers $n,c,d$ ($2 \leq n \leq 2\cdot10^5$; $1 \leq c \leq 10^{16}$; $1 \leq d \leq 2\cdot10^5$) β the number of quests, the number of coins you need, and the number of days.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^9$) β the rewards for the quests.
The sum of $n$ over all test cases does not exceed $2\cdot10^5$, and the sum of $d$ over all test cases does not exceed $2\cdot10^5$.
-----Output-----
For each test case, output one of the following.
If no such $k$ exists, output Impossible.
If $k$ can be arbitrarily large, output Infinity.
Otherwise, output a single integer β the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days.
Please note, the checker is case-sensitive, and you should output strings exactly as they are given.
-----Examples-----
Input
6
2 5 4
1 2
2 20 10
100 10
3 100 3
7 2 6
4 20 3
4 5 6 7
4 100000000000 2022
8217734 927368 26389746 627896974
2 20 4
5 1
Output
2
Infinity
Impossible
1
12
0
-----Note-----
In the first test case, one way to earn $5$ coins over $4$ days with $k=2$ is as follows:
Day 1: do quest 2, and earn $2$ coins.
Day 2: do quest 1, and earn $1$ coin.
Day 3: do nothing.
Day 4: do quest 2, and earn $2$ coins.
In total, we earned $2+1+2=5$ coins.
In the second test case, we can make over $20$ coins on the first day itself by doing the first quest to earn $100$ coins, so the value of $k$ can be arbitrarily large, since we never need to do another quest.
In the third test case, no matter what we do, we can't earn $100$ coins over $3$ days.
|
from itertools import accumulate, count, dropwhile
for _ in range(int(input())):
n, c, d = map(int, input().split())
rwds = list(sorted(map(int, input().split()), reverse=True))
sums = [0] + list(accumulate(rwds))
if sums[min(d, len(rwds))] >= c:
print("Infinity")
elif d // len(rwds) * sums[-1] + sums[d % len(rwds)] >= c:
print(
next(
dropwhile(
lambda k: d // (k + 1) * sums[-1]
+ sums[min(d % (k + 1), len(rwds))]
>= c,
count(d * sums[-1] // (c + sums[-1]) - 1),
)
)
- 1
)
else:
try:
print(
next(
dropwhile(
lambda k: d // (k + 1) * sums[k + 1] + sums[d % (k + 1)] < c,
count(len(rwds) - 1, -1),
)
)
)
except:
print("Impossible")
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING IF BIN_OP BIN_OP BIN_OP VAR FUNC_CALL VAR VAR VAR NUMBER VAR BIN_OP VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING
|
There are $n$ quests. If you complete the $i$-th quest, you will gain $a_i$ coins. You can only complete at most one quest per day. However, once you complete a quest, you cannot do the same quest again for $k$ days. (For example, if $k=2$ and you do quest $1$ on day $1$, then you cannot do it on day $2$ or $3$, but you can do it again on day $4$.)
You are given two integers $c$ and $d$. Find the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days. If no such $k$ exists, output Impossible. If $k$ can be arbitrarily large, output Infinity.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 10^4$) β the number of test cases. The description of the test cases follows.
The first line of each test case contains three integers $n,c,d$ ($2 \leq n \leq 2\cdot10^5$; $1 \leq c \leq 10^{16}$; $1 \leq d \leq 2\cdot10^5$) β the number of quests, the number of coins you need, and the number of days.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^9$) β the rewards for the quests.
The sum of $n$ over all test cases does not exceed $2\cdot10^5$, and the sum of $d$ over all test cases does not exceed $2\cdot10^5$.
-----Output-----
For each test case, output one of the following.
If no such $k$ exists, output Impossible.
If $k$ can be arbitrarily large, output Infinity.
Otherwise, output a single integer β the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days.
Please note, the checker is case-sensitive, and you should output strings exactly as they are given.
-----Examples-----
Input
6
2 5 4
1 2
2 20 10
100 10
3 100 3
7 2 6
4 20 3
4 5 6 7
4 100000000000 2022
8217734 927368 26389746 627896974
2 20 4
5 1
Output
2
Infinity
Impossible
1
12
0
-----Note-----
In the first test case, one way to earn $5$ coins over $4$ days with $k=2$ is as follows:
Day 1: do quest 2, and earn $2$ coins.
Day 2: do quest 1, and earn $1$ coin.
Day 3: do nothing.
Day 4: do quest 2, and earn $2$ coins.
In total, we earned $2+1+2=5$ coins.
In the second test case, we can make over $20$ coins on the first day itself by doing the first quest to earn $100$ coins, so the value of $k$ can be arbitrarily large, since we never need to do another quest.
In the third test case, no matter what we do, we can't earn $100$ coins over $3$ days.
|
import sys
input = sys.stdin.readline
for t in range(int(input())):
n, c, d = map(int, input().split())
lst = list(map(int, input().split()))
if d > n:
for i in range(d - n):
lst.append(0)
n = len(lst)
lst.sort()
lst = lst[n - d :]
sm = sum(lst)
if sm >= c:
sys.stdout.write("Infinity" + "\n")
continue
if lst[-1] * d < c:
sys.stdout.write("Impossible" + "\n")
continue
res = []
temp = 0
for i in reversed(lst):
temp += i
res.append(temp)
for i in reversed(range(1, d)):
a = d // i
b = d % i
temp = a * res[i - 1]
if b != 0:
temp += res[(b - 1) % len(res)]
if temp >= c:
sys.stdout.write(str(i - 1) + "\n")
break
|
IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING STRING IF BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP STRING STRING ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR BIN_OP BIN_OP VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER STRING
|
There are $n$ quests. If you complete the $i$-th quest, you will gain $a_i$ coins. You can only complete at most one quest per day. However, once you complete a quest, you cannot do the same quest again for $k$ days. (For example, if $k=2$ and you do quest $1$ on day $1$, then you cannot do it on day $2$ or $3$, but you can do it again on day $4$.)
You are given two integers $c$ and $d$. Find the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days. If no such $k$ exists, output Impossible. If $k$ can be arbitrarily large, output Infinity.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 10^4$) β the number of test cases. The description of the test cases follows.
The first line of each test case contains three integers $n,c,d$ ($2 \leq n \leq 2\cdot10^5$; $1 \leq c \leq 10^{16}$; $1 \leq d \leq 2\cdot10^5$) β the number of quests, the number of coins you need, and the number of days.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^9$) β the rewards for the quests.
The sum of $n$ over all test cases does not exceed $2\cdot10^5$, and the sum of $d$ over all test cases does not exceed $2\cdot10^5$.
-----Output-----
For each test case, output one of the following.
If no such $k$ exists, output Impossible.
If $k$ can be arbitrarily large, output Infinity.
Otherwise, output a single integer β the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days.
Please note, the checker is case-sensitive, and you should output strings exactly as they are given.
-----Examples-----
Input
6
2 5 4
1 2
2 20 10
100 10
3 100 3
7 2 6
4 20 3
4 5 6 7
4 100000000000 2022
8217734 927368 26389746 627896974
2 20 4
5 1
Output
2
Infinity
Impossible
1
12
0
-----Note-----
In the first test case, one way to earn $5$ coins over $4$ days with $k=2$ is as follows:
Day 1: do quest 2, and earn $2$ coins.
Day 2: do quest 1, and earn $1$ coin.
Day 3: do nothing.
Day 4: do quest 2, and earn $2$ coins.
In total, we earned $2+1+2=5$ coins.
In the second test case, we can make over $20$ coins on the first day itself by doing the first quest to earn $100$ coins, so the value of $k$ can be arbitrarily large, since we never need to do another quest.
In the third test case, no matter what we do, we can't earn $100$ coins over $3$ days.
|
t = int(input())
for h in range(t):
n, c, d = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a, reverse=True)
b = [0] * (n + 1)
for i in range(n):
b[i + 1] = b[i] + a[i]
f = -1
for k in range(d + 10):
s = b[min(k + 1, n)] * (d // (k + 1)) + b[min(d % (k + 1), n)]
if s >= c:
f = k
if f == -1:
print("Impossible")
elif f == d + 9:
print("Infinity")
else:
print(f)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
|
There are $n$ quests. If you complete the $i$-th quest, you will gain $a_i$ coins. You can only complete at most one quest per day. However, once you complete a quest, you cannot do the same quest again for $k$ days. (For example, if $k=2$ and you do quest $1$ on day $1$, then you cannot do it on day $2$ or $3$, but you can do it again on day $4$.)
You are given two integers $c$ and $d$. Find the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days. If no such $k$ exists, output Impossible. If $k$ can be arbitrarily large, output Infinity.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 10^4$) β the number of test cases. The description of the test cases follows.
The first line of each test case contains three integers $n,c,d$ ($2 \leq n \leq 2\cdot10^5$; $1 \leq c \leq 10^{16}$; $1 \leq d \leq 2\cdot10^5$) β the number of quests, the number of coins you need, and the number of days.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^9$) β the rewards for the quests.
The sum of $n$ over all test cases does not exceed $2\cdot10^5$, and the sum of $d$ over all test cases does not exceed $2\cdot10^5$.
-----Output-----
For each test case, output one of the following.
If no such $k$ exists, output Impossible.
If $k$ can be arbitrarily large, output Infinity.
Otherwise, output a single integer β the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days.
Please note, the checker is case-sensitive, and you should output strings exactly as they are given.
-----Examples-----
Input
6
2 5 4
1 2
2 20 10
100 10
3 100 3
7 2 6
4 20 3
4 5 6 7
4 100000000000 2022
8217734 927368 26389746 627896974
2 20 4
5 1
Output
2
Infinity
Impossible
1
12
0
-----Note-----
In the first test case, one way to earn $5$ coins over $4$ days with $k=2$ is as follows:
Day 1: do quest 2, and earn $2$ coins.
Day 2: do quest 1, and earn $1$ coin.
Day 3: do nothing.
Day 4: do quest 2, and earn $2$ coins.
In total, we earned $2+1+2=5$ coins.
In the second test case, we can make over $20$ coins on the first day itself by doing the first quest to earn $100$ coins, so the value of $k$ can be arbitrarily large, since we never need to do another quest.
In the third test case, no matter what we do, we can't earn $100$ coins over $3$ days.
|
arr = [4, 4, 2, 1, 2, 2]
d = 8
c = 22
def check(k):
num = min(k, len(arr) - 1)
num = min(d - 1, num)
multi = d // (k + 1)
modul = d % (k + 1)
modul = min(modul, len(arr))
sum = 0
for i in range(0, num + 1):
sum += arr[i]
if multi > 0:
sum *= multi
if modul > 0:
for i in range(modul):
sum += arr[i]
return sum
t = int(input())
while t > 0:
t -= 1
n, c, d = map(int, input().split(" "))
arr = list(map(int, input().split(" ")))
l, r = 0, d
maxK = -1
arr.sort(reverse=True)
while l <= r:
mid = (l + r) // 2
sum = check(mid)
if sum >= c:
l = mid + 1
maxK = max(maxK, mid)
else:
r = mid - 1
if l >= d:
print("Infinity")
elif maxK >= 0:
print(maxK)
else:
print("Impossible")
|
ASSIGN VAR LIST NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR IF VAR NUMBER VAR VAR IF VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
|
There are $n$ quests. If you complete the $i$-th quest, you will gain $a_i$ coins. You can only complete at most one quest per day. However, once you complete a quest, you cannot do the same quest again for $k$ days. (For example, if $k=2$ and you do quest $1$ on day $1$, then you cannot do it on day $2$ or $3$, but you can do it again on day $4$.)
You are given two integers $c$ and $d$. Find the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days. If no such $k$ exists, output Impossible. If $k$ can be arbitrarily large, output Infinity.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 10^4$) β the number of test cases. The description of the test cases follows.
The first line of each test case contains three integers $n,c,d$ ($2 \leq n \leq 2\cdot10^5$; $1 \leq c \leq 10^{16}$; $1 \leq d \leq 2\cdot10^5$) β the number of quests, the number of coins you need, and the number of days.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^9$) β the rewards for the quests.
The sum of $n$ over all test cases does not exceed $2\cdot10^5$, and the sum of $d$ over all test cases does not exceed $2\cdot10^5$.
-----Output-----
For each test case, output one of the following.
If no such $k$ exists, output Impossible.
If $k$ can be arbitrarily large, output Infinity.
Otherwise, output a single integer β the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days.
Please note, the checker is case-sensitive, and you should output strings exactly as they are given.
-----Examples-----
Input
6
2 5 4
1 2
2 20 10
100 10
3 100 3
7 2 6
4 20 3
4 5 6 7
4 100000000000 2022
8217734 927368 26389746 627896974
2 20 4
5 1
Output
2
Infinity
Impossible
1
12
0
-----Note-----
In the first test case, one way to earn $5$ coins over $4$ days with $k=2$ is as follows:
Day 1: do quest 2, and earn $2$ coins.
Day 2: do quest 1, and earn $1$ coin.
Day 3: do nothing.
Day 4: do quest 2, and earn $2$ coins.
In total, we earned $2+1+2=5$ coins.
In the second test case, we can make over $20$ coins on the first day itself by doing the first quest to earn $100$ coins, so the value of $k$ can be arbitrarily large, since we never need to do another quest.
In the third test case, no matter what we do, we can't earn $100$ coins over $3$ days.
|
for __ in range(int(input())):
n, c, d = map(int, input().split())
a = sorted(list(map(int, input().split())), reverse=True)
sumlst = [0]
for i in a:
sumlst.append(sumlst[-1] + i)
ans = "Impossible"
for k in range(d + 1):
if sumlst[min(n, k + 1)] * (d // (k + 1)) + sumlst[min(n, d % (k + 1))] >= c:
ans = k
print("Infinity" if ans == d else ans)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER ASSIGN VAR LIST NUMBER FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR STRING VAR
|
There are $n$ quests. If you complete the $i$-th quest, you will gain $a_i$ coins. You can only complete at most one quest per day. However, once you complete a quest, you cannot do the same quest again for $k$ days. (For example, if $k=2$ and you do quest $1$ on day $1$, then you cannot do it on day $2$ or $3$, but you can do it again on day $4$.)
You are given two integers $c$ and $d$. Find the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days. If no such $k$ exists, output Impossible. If $k$ can be arbitrarily large, output Infinity.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 10^4$) β the number of test cases. The description of the test cases follows.
The first line of each test case contains three integers $n,c,d$ ($2 \leq n \leq 2\cdot10^5$; $1 \leq c \leq 10^{16}$; $1 \leq d \leq 2\cdot10^5$) β the number of quests, the number of coins you need, and the number of days.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^9$) β the rewards for the quests.
The sum of $n$ over all test cases does not exceed $2\cdot10^5$, and the sum of $d$ over all test cases does not exceed $2\cdot10^5$.
-----Output-----
For each test case, output one of the following.
If no such $k$ exists, output Impossible.
If $k$ can be arbitrarily large, output Infinity.
Otherwise, output a single integer β the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days.
Please note, the checker is case-sensitive, and you should output strings exactly as they are given.
-----Examples-----
Input
6
2 5 4
1 2
2 20 10
100 10
3 100 3
7 2 6
4 20 3
4 5 6 7
4 100000000000 2022
8217734 927368 26389746 627896974
2 20 4
5 1
Output
2
Infinity
Impossible
1
12
0
-----Note-----
In the first test case, one way to earn $5$ coins over $4$ days with $k=2$ is as follows:
Day 1: do quest 2, and earn $2$ coins.
Day 2: do quest 1, and earn $1$ coin.
Day 3: do nothing.
Day 4: do quest 2, and earn $2$ coins.
In total, we earned $2+1+2=5$ coins.
In the second test case, we can make over $20$ coins on the first day itself by doing the first quest to earn $100$ coins, so the value of $k$ can be arbitrarily large, since we never need to do another quest.
In the third test case, no matter what we do, we can't earn $100$ coins over $3$ days.
|
T = int(input())
for hasbulla in range(T):
n, c, d = [int(x) for x in map(int, input().split())]
t = list(map(int, input().split()))
t.sort(reverse=True)
if t[0] * d < c:
print("Impossible")
continue
l = 0
r = d + 9
ans = 0
while l != r:
mid = (l + r) // 2
essa = 0
for i in range(d):
if i % mid < n:
essa += t[i % mid]
if essa >= c:
l = mid + 1
ans = mid
else:
r = mid
if ans == d + 8:
print("Infinity")
continue
print(ans - 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
There are $n$ quests. If you complete the $i$-th quest, you will gain $a_i$ coins. You can only complete at most one quest per day. However, once you complete a quest, you cannot do the same quest again for $k$ days. (For example, if $k=2$ and you do quest $1$ on day $1$, then you cannot do it on day $2$ or $3$, but you can do it again on day $4$.)
You are given two integers $c$ and $d$. Find the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days. If no such $k$ exists, output Impossible. If $k$ can be arbitrarily large, output Infinity.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 10^4$) β the number of test cases. The description of the test cases follows.
The first line of each test case contains three integers $n,c,d$ ($2 \leq n \leq 2\cdot10^5$; $1 \leq c \leq 10^{16}$; $1 \leq d \leq 2\cdot10^5$) β the number of quests, the number of coins you need, and the number of days.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^9$) β the rewards for the quests.
The sum of $n$ over all test cases does not exceed $2\cdot10^5$, and the sum of $d$ over all test cases does not exceed $2\cdot10^5$.
-----Output-----
For each test case, output one of the following.
If no such $k$ exists, output Impossible.
If $k$ can be arbitrarily large, output Infinity.
Otherwise, output a single integer β the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days.
Please note, the checker is case-sensitive, and you should output strings exactly as they are given.
-----Examples-----
Input
6
2 5 4
1 2
2 20 10
100 10
3 100 3
7 2 6
4 20 3
4 5 6 7
4 100000000000 2022
8217734 927368 26389746 627896974
2 20 4
5 1
Output
2
Infinity
Impossible
1
12
0
-----Note-----
In the first test case, one way to earn $5$ coins over $4$ days with $k=2$ is as follows:
Day 1: do quest 2, and earn $2$ coins.
Day 2: do quest 1, and earn $1$ coin.
Day 3: do nothing.
Day 4: do quest 2, and earn $2$ coins.
In total, we earned $2+1+2=5$ coins.
In the second test case, we can make over $20$ coins on the first day itself by doing the first quest to earn $100$ coins, so the value of $k$ can be arbitrarily large, since we never need to do another quest.
In the third test case, no matter what we do, we can't earn $100$ coins over $3$ days.
|
t = int(input())
def possible(k, n, c, d, nums):
ssum = 0
for i in range(d):
try:
a = nums[i % (k + 1)]
except:
a = 0
ssum += a
return ssum >= c
def solve():
n, c, d = [int(x) for x in input().split()]
nums = [int(x) for x in input().split()]
nums.sort(reverse=True)
l = 0
r = d - 1
if sum(nums[: min(d, n, len(nums))]) >= c:
print("Infinity")
return
while True:
if r - l <= 3:
for k in range(r, l - 1, -1):
if possible(k, n, c, d, nums):
print(k)
return
print("Impossible")
return
k = (l + r) // 2
pos = possible(k, n, c, d, nums)
if pos:
l = k
else:
r = k - 1
for _ in range(t):
solve()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING RETURN WHILE NUMBER IF BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR VAR IF VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
There are $n$ quests. If you complete the $i$-th quest, you will gain $a_i$ coins. You can only complete at most one quest per day. However, once you complete a quest, you cannot do the same quest again for $k$ days. (For example, if $k=2$ and you do quest $1$ on day $1$, then you cannot do it on day $2$ or $3$, but you can do it again on day $4$.)
You are given two integers $c$ and $d$. Find the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days. If no such $k$ exists, output Impossible. If $k$ can be arbitrarily large, output Infinity.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 10^4$) β the number of test cases. The description of the test cases follows.
The first line of each test case contains three integers $n,c,d$ ($2 \leq n \leq 2\cdot10^5$; $1 \leq c \leq 10^{16}$; $1 \leq d \leq 2\cdot10^5$) β the number of quests, the number of coins you need, and the number of days.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^9$) β the rewards for the quests.
The sum of $n$ over all test cases does not exceed $2\cdot10^5$, and the sum of $d$ over all test cases does not exceed $2\cdot10^5$.
-----Output-----
For each test case, output one of the following.
If no such $k$ exists, output Impossible.
If $k$ can be arbitrarily large, output Infinity.
Otherwise, output a single integer β the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days.
Please note, the checker is case-sensitive, and you should output strings exactly as they are given.
-----Examples-----
Input
6
2 5 4
1 2
2 20 10
100 10
3 100 3
7 2 6
4 20 3
4 5 6 7
4 100000000000 2022
8217734 927368 26389746 627896974
2 20 4
5 1
Output
2
Infinity
Impossible
1
12
0
-----Note-----
In the first test case, one way to earn $5$ coins over $4$ days with $k=2$ is as follows:
Day 1: do quest 2, and earn $2$ coins.
Day 2: do quest 1, and earn $1$ coin.
Day 3: do nothing.
Day 4: do quest 2, and earn $2$ coins.
In total, we earned $2+1+2=5$ coins.
In the second test case, we can make over $20$ coins on the first day itself by doing the first quest to earn $100$ coins, so the value of $k$ can be arbitrarily large, since we never need to do another quest.
In the third test case, no matter what we do, we can't earn $100$ coins over $3$ days.
|
def N():
return int(input())
def A():
return [int(x) for x in input().split()]
def S():
return input()
for _ in range(N()):
n, c, d = A()
l = 0
if "codeforces" == 28226329:
print("Tanmay")
a = A()
h = 10**18
a.sort()
a.reverse()
while l < h:
k = (h + 1 + l) // 2
if c > d // k * sum(a[: min(k, n)]) + sum(a[: min(d % k, n)]):
h = k - 1
else:
l = k
if l == 10**18:
print("Infinity")
continue
if l == 0:
print("Impossible")
continue
print(l - 1)
|
FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR NUMBER IF STRING NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR NUMBER VAR NUMBER IF VAR BIN_OP BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
There are $n$ quests. If you complete the $i$-th quest, you will gain $a_i$ coins. You can only complete at most one quest per day. However, once you complete a quest, you cannot do the same quest again for $k$ days. (For example, if $k=2$ and you do quest $1$ on day $1$, then you cannot do it on day $2$ or $3$, but you can do it again on day $4$.)
You are given two integers $c$ and $d$. Find the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days. If no such $k$ exists, output Impossible. If $k$ can be arbitrarily large, output Infinity.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 10^4$) β the number of test cases. The description of the test cases follows.
The first line of each test case contains three integers $n,c,d$ ($2 \leq n \leq 2\cdot10^5$; $1 \leq c \leq 10^{16}$; $1 \leq d \leq 2\cdot10^5$) β the number of quests, the number of coins you need, and the number of days.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^9$) β the rewards for the quests.
The sum of $n$ over all test cases does not exceed $2\cdot10^5$, and the sum of $d$ over all test cases does not exceed $2\cdot10^5$.
-----Output-----
For each test case, output one of the following.
If no such $k$ exists, output Impossible.
If $k$ can be arbitrarily large, output Infinity.
Otherwise, output a single integer β the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days.
Please note, the checker is case-sensitive, and you should output strings exactly as they are given.
-----Examples-----
Input
6
2 5 4
1 2
2 20 10
100 10
3 100 3
7 2 6
4 20 3
4 5 6 7
4 100000000000 2022
8217734 927368 26389746 627896974
2 20 4
5 1
Output
2
Infinity
Impossible
1
12
0
-----Note-----
In the first test case, one way to earn $5$ coins over $4$ days with $k=2$ is as follows:
Day 1: do quest 2, and earn $2$ coins.
Day 2: do quest 1, and earn $1$ coin.
Day 3: do nothing.
Day 4: do quest 2, and earn $2$ coins.
In total, we earned $2+1+2=5$ coins.
In the second test case, we can make over $20$ coins on the first day itself by doing the first quest to earn $100$ coins, so the value of $k$ can be arbitrarily large, since we never need to do another quest.
In the third test case, no matter what we do, we can't earn $100$ coins over $3$ days.
|
import sys
input = sys.stdin.readline
nel = int(input())
for i in range(nel):
data = list(map(int, input().split(" ")))
n_quest = data[0]
n_coins = data[1]
n_days = data[2]
data = list(map(int, input().split(" ")))
rew = sorted(data)[::-1]
if rew[0] >= n_coins:
print("Infinity")
continue
def getSum(k):
kk = k + 1
return sum(rew[:kk]) * (n_days // kk) + sum(rew[: n_days % kk])
h_k = -1
if n_days < 100:
k = 0
while k < n_days:
sum_rews = getSum(k)
if sum_rews >= n_coins:
h_k = k
else:
k = n_days
break
k += 1
else:
s, e = 0, n_days - 1
while s <= e:
m = (s + e) // 2
val = getSum(m) >= n_coins
if val:
s = m + 1
else:
e = m - 1
h_k = s - 1
if h_k == n_days - 1:
print("Infinity")
elif h_k >= 0:
print(h_k)
else:
print("Impossible")
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR EXPR FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER RETURN BIN_OP BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
|
There are $n$ quests. If you complete the $i$-th quest, you will gain $a_i$ coins. You can only complete at most one quest per day. However, once you complete a quest, you cannot do the same quest again for $k$ days. (For example, if $k=2$ and you do quest $1$ on day $1$, then you cannot do it on day $2$ or $3$, but you can do it again on day $4$.)
You are given two integers $c$ and $d$. Find the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days. If no such $k$ exists, output Impossible. If $k$ can be arbitrarily large, output Infinity.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 10^4$) β the number of test cases. The description of the test cases follows.
The first line of each test case contains three integers $n,c,d$ ($2 \leq n \leq 2\cdot10^5$; $1 \leq c \leq 10^{16}$; $1 \leq d \leq 2\cdot10^5$) β the number of quests, the number of coins you need, and the number of days.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^9$) β the rewards for the quests.
The sum of $n$ over all test cases does not exceed $2\cdot10^5$, and the sum of $d$ over all test cases does not exceed $2\cdot10^5$.
-----Output-----
For each test case, output one of the following.
If no such $k$ exists, output Impossible.
If $k$ can be arbitrarily large, output Infinity.
Otherwise, output a single integer β the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days.
Please note, the checker is case-sensitive, and you should output strings exactly as they are given.
-----Examples-----
Input
6
2 5 4
1 2
2 20 10
100 10
3 100 3
7 2 6
4 20 3
4 5 6 7
4 100000000000 2022
8217734 927368 26389746 627896974
2 20 4
5 1
Output
2
Infinity
Impossible
1
12
0
-----Note-----
In the first test case, one way to earn $5$ coins over $4$ days with $k=2$ is as follows:
Day 1: do quest 2, and earn $2$ coins.
Day 2: do quest 1, and earn $1$ coin.
Day 3: do nothing.
Day 4: do quest 2, and earn $2$ coins.
In total, we earned $2+1+2=5$ coins.
In the second test case, we can make over $20$ coins on the first day itself by doing the first quest to earn $100$ coins, so the value of $k$ can be arbitrarily large, since we never need to do another quest.
In the third test case, no matter what we do, we can't earn $100$ coins over $3$ days.
|
def f(k, s, d):
ck = s[min(k, n - 1)] * (d // (k + 1))
if d % (k + 1) > 0:
ck += s[min(d % (k + 1) - 1, n - 1)]
return ck
T = int(input())
for t in range(T):
n, c, d = [int(x) for x in input().split()]
a = [int(x) for x in input().split()]
a.sort(reverse=True)
s = [0] * n
s[0] = a[0]
for i in range(1, n):
s[i] = s[i - 1] + a[i]
if s[min(d - 1, n - 1)] >= c:
print("Infinity")
continue
if s[0] * d < c:
print("Impossible")
continue
l = 0
r = d
while r > l:
k = (l + r + 1) // 2
ck = f(k, s, d)
if ck >= c:
l = k
else:
r = k - 1
print(l)
|
FUNC_DEF ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are $n$ quests. If you complete the $i$-th quest, you will gain $a_i$ coins. You can only complete at most one quest per day. However, once you complete a quest, you cannot do the same quest again for $k$ days. (For example, if $k=2$ and you do quest $1$ on day $1$, then you cannot do it on day $2$ or $3$, but you can do it again on day $4$.)
You are given two integers $c$ and $d$. Find the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days. If no such $k$ exists, output Impossible. If $k$ can be arbitrarily large, output Infinity.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 10^4$) β the number of test cases. The description of the test cases follows.
The first line of each test case contains three integers $n,c,d$ ($2 \leq n \leq 2\cdot10^5$; $1 \leq c \leq 10^{16}$; $1 \leq d \leq 2\cdot10^5$) β the number of quests, the number of coins you need, and the number of days.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^9$) β the rewards for the quests.
The sum of $n$ over all test cases does not exceed $2\cdot10^5$, and the sum of $d$ over all test cases does not exceed $2\cdot10^5$.
-----Output-----
For each test case, output one of the following.
If no such $k$ exists, output Impossible.
If $k$ can be arbitrarily large, output Infinity.
Otherwise, output a single integer β the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days.
Please note, the checker is case-sensitive, and you should output strings exactly as they are given.
-----Examples-----
Input
6
2 5 4
1 2
2 20 10
100 10
3 100 3
7 2 6
4 20 3
4 5 6 7
4 100000000000 2022
8217734 927368 26389746 627896974
2 20 4
5 1
Output
2
Infinity
Impossible
1
12
0
-----Note-----
In the first test case, one way to earn $5$ coins over $4$ days with $k=2$ is as follows:
Day 1: do quest 2, and earn $2$ coins.
Day 2: do quest 1, and earn $1$ coin.
Day 3: do nothing.
Day 4: do quest 2, and earn $2$ coins.
In total, we earned $2+1+2=5$ coins.
In the second test case, we can make over $20$ coins on the first day itself by doing the first quest to earn $100$ coins, so the value of $k$ can be arbitrarily large, since we never need to do another quest.
In the third test case, no matter what we do, we can't earn $100$ coins over $3$ days.
|
def check(mid, a, d, c):
num = mid + 1
lun = d // num
lunsum = a[min(num, len(a)) - 1]
res = lun * lunsum
yu = d % num
if yu:
res += a[min(yu, len(a)) - 1]
if res >= c:
return 1
else:
return 0
def solve():
n, c, d = input().split(" ")
n = int(n)
c = int(c)
d = int(d)
a = [int(x) for x in input().split(" ")]
ff = 0
if d <= n:
s = sum(a)
if s >= c:
ff = 1
maxn = max(a)
if maxn * d < c:
print("Impossible")
return
l = 0
r = 600000
a.sort(reverse=True)
for ev in range(len(a)):
if ev == 0:
continue
a[ev] += a[ev - 1]
check(1, a, d, c)
while l < r:
mid = (l + r + 1) // 2
if check(mid, a, d, c) == 1:
l = mid
else:
r = mid - 1
if l == 600000:
print("Infinity")
else:
print(l)
t = int(input())
for each in range(t):
solve()
|
FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR STRING RETURN ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
There are $n$ quests. If you complete the $i$-th quest, you will gain $a_i$ coins. You can only complete at most one quest per day. However, once you complete a quest, you cannot do the same quest again for $k$ days. (For example, if $k=2$ and you do quest $1$ on day $1$, then you cannot do it on day $2$ or $3$, but you can do it again on day $4$.)
You are given two integers $c$ and $d$. Find the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days. If no such $k$ exists, output Impossible. If $k$ can be arbitrarily large, output Infinity.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 10^4$) β the number of test cases. The description of the test cases follows.
The first line of each test case contains three integers $n,c,d$ ($2 \leq n \leq 2\cdot10^5$; $1 \leq c \leq 10^{16}$; $1 \leq d \leq 2\cdot10^5$) β the number of quests, the number of coins you need, and the number of days.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^9$) β the rewards for the quests.
The sum of $n$ over all test cases does not exceed $2\cdot10^5$, and the sum of $d$ over all test cases does not exceed $2\cdot10^5$.
-----Output-----
For each test case, output one of the following.
If no such $k$ exists, output Impossible.
If $k$ can be arbitrarily large, output Infinity.
Otherwise, output a single integer β the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days.
Please note, the checker is case-sensitive, and you should output strings exactly as they are given.
-----Examples-----
Input
6
2 5 4
1 2
2 20 10
100 10
3 100 3
7 2 6
4 20 3
4 5 6 7
4 100000000000 2022
8217734 927368 26389746 627896974
2 20 4
5 1
Output
2
Infinity
Impossible
1
12
0
-----Note-----
In the first test case, one way to earn $5$ coins over $4$ days with $k=2$ is as follows:
Day 1: do quest 2, and earn $2$ coins.
Day 2: do quest 1, and earn $1$ coin.
Day 3: do nothing.
Day 4: do quest 2, and earn $2$ coins.
In total, we earned $2+1+2=5$ coins.
In the second test case, we can make over $20$ coins on the first day itself by doing the first quest to earn $100$ coins, so the value of $k$ can be arbitrarily large, since we never need to do another quest.
In the third test case, no matter what we do, we can't earn $100$ coins over $3$ days.
|
for _ in range(int(input())):
n, c, d = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A)[::-1]
if sum(A[:d]) >= c:
print("Infinity")
elif A[0] * d < c:
print("Impossible")
else:
l, r = 0, d
mid = (l + r + 1) // 2
while l < r:
selecsum = sum(A[: mid + 1])
numselec = d // (mid + 1)
remain = d % (mid + 1)
coins = numselec * selecsum + sum(A[:remain])
if coins >= c:
l = mid
else:
r = mid - 1
mid = (l + r + 1) // 2
print(mid)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
There are $n$ quests. If you complete the $i$-th quest, you will gain $a_i$ coins. You can only complete at most one quest per day. However, once you complete a quest, you cannot do the same quest again for $k$ days. (For example, if $k=2$ and you do quest $1$ on day $1$, then you cannot do it on day $2$ or $3$, but you can do it again on day $4$.)
You are given two integers $c$ and $d$. Find the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days. If no such $k$ exists, output Impossible. If $k$ can be arbitrarily large, output Infinity.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 10^4$) β the number of test cases. The description of the test cases follows.
The first line of each test case contains three integers $n,c,d$ ($2 \leq n \leq 2\cdot10^5$; $1 \leq c \leq 10^{16}$; $1 \leq d \leq 2\cdot10^5$) β the number of quests, the number of coins you need, and the number of days.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^9$) β the rewards for the quests.
The sum of $n$ over all test cases does not exceed $2\cdot10^5$, and the sum of $d$ over all test cases does not exceed $2\cdot10^5$.
-----Output-----
For each test case, output one of the following.
If no such $k$ exists, output Impossible.
If $k$ can be arbitrarily large, output Infinity.
Otherwise, output a single integer β the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days.
Please note, the checker is case-sensitive, and you should output strings exactly as they are given.
-----Examples-----
Input
6
2 5 4
1 2
2 20 10
100 10
3 100 3
7 2 6
4 20 3
4 5 6 7
4 100000000000 2022
8217734 927368 26389746 627896974
2 20 4
5 1
Output
2
Infinity
Impossible
1
12
0
-----Note-----
In the first test case, one way to earn $5$ coins over $4$ days with $k=2$ is as follows:
Day 1: do quest 2, and earn $2$ coins.
Day 2: do quest 1, and earn $1$ coin.
Day 3: do nothing.
Day 4: do quest 2, and earn $2$ coins.
In total, we earned $2+1+2=5$ coins.
In the second test case, we can make over $20$ coins on the first day itself by doing the first quest to earn $100$ coins, so the value of $k$ can be arbitrarily large, since we never need to do another quest.
In the third test case, no matter what we do, we can't earn $100$ coins over $3$ days.
|
def solve():
n, c, d = tuple(map(int, input().split()))
a = list(map(int, input().split()))
a.sort(reverse=True)
agg = 0
for i in range(n):
if i >= d:
break
agg += a[i]
a[i] = agg
if agg >= c:
print("Infinity")
return
for i in range(d - 1, -1, -1):
if (
a[min(i, n - 1)] * (d // (i + 1))
+ (a[min(d % (i + 1) - 1, n - 1)] if d % (i + 1) != 0 else 0)
>= c
):
print(str(i))
return
print("Impossible")
t = int(input())
for _ in range(t):
solve()
|
FUNC_DEF ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING RETURN FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP BIN_OP VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR NUMBER NUMBER VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR RETURN EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
There are $n$ quests. If you complete the $i$-th quest, you will gain $a_i$ coins. You can only complete at most one quest per day. However, once you complete a quest, you cannot do the same quest again for $k$ days. (For example, if $k=2$ and you do quest $1$ on day $1$, then you cannot do it on day $2$ or $3$, but you can do it again on day $4$.)
You are given two integers $c$ and $d$. Find the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days. If no such $k$ exists, output Impossible. If $k$ can be arbitrarily large, output Infinity.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 10^4$) β the number of test cases. The description of the test cases follows.
The first line of each test case contains three integers $n,c,d$ ($2 \leq n \leq 2\cdot10^5$; $1 \leq c \leq 10^{16}$; $1 \leq d \leq 2\cdot10^5$) β the number of quests, the number of coins you need, and the number of days.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^9$) β the rewards for the quests.
The sum of $n$ over all test cases does not exceed $2\cdot10^5$, and the sum of $d$ over all test cases does not exceed $2\cdot10^5$.
-----Output-----
For each test case, output one of the following.
If no such $k$ exists, output Impossible.
If $k$ can be arbitrarily large, output Infinity.
Otherwise, output a single integer β the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days.
Please note, the checker is case-sensitive, and you should output strings exactly as they are given.
-----Examples-----
Input
6
2 5 4
1 2
2 20 10
100 10
3 100 3
7 2 6
4 20 3
4 5 6 7
4 100000000000 2022
8217734 927368 26389746 627896974
2 20 4
5 1
Output
2
Infinity
Impossible
1
12
0
-----Note-----
In the first test case, one way to earn $5$ coins over $4$ days with $k=2$ is as follows:
Day 1: do quest 2, and earn $2$ coins.
Day 2: do quest 1, and earn $1$ coin.
Day 3: do nothing.
Day 4: do quest 2, and earn $2$ coins.
In total, we earned $2+1+2=5$ coins.
In the second test case, we can make over $20$ coins on the first day itself by doing the first quest to earn $100$ coins, so the value of $k$ can be arbitrarily large, since we never need to do another quest.
In the third test case, no matter what we do, we can't earn $100$ coins over $3$ days.
|
T = int(input())
while T > 0:
T -= 1
n, c, d = map(int, input().split())
arr = list(map(int, input().split()))
aoi = sorted(arr, reverse=True)
l = 1
r = d + 1
sum = 0
for i in range(len(aoi)):
sum += aoi[i]
def check(k):
sana = 0
for i in range(d):
if i % k < n:
sana += aoi[i % k]
return sana >= c
while l < r:
m = (l + r) // 2
if check(m):
l = m + 1
else:
r = m
if l == 1:
print("Impossible")
elif l == d + 1:
print("Infinity")
else:
print(l - 2)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR VAR RETURN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
There are $n$ quests. If you complete the $i$-th quest, you will gain $a_i$ coins. You can only complete at most one quest per day. However, once you complete a quest, you cannot do the same quest again for $k$ days. (For example, if $k=2$ and you do quest $1$ on day $1$, then you cannot do it on day $2$ or $3$, but you can do it again on day $4$.)
You are given two integers $c$ and $d$. Find the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days. If no such $k$ exists, output Impossible. If $k$ can be arbitrarily large, output Infinity.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 10^4$) β the number of test cases. The description of the test cases follows.
The first line of each test case contains three integers $n,c,d$ ($2 \leq n \leq 2\cdot10^5$; $1 \leq c \leq 10^{16}$; $1 \leq d \leq 2\cdot10^5$) β the number of quests, the number of coins you need, and the number of days.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^9$) β the rewards for the quests.
The sum of $n$ over all test cases does not exceed $2\cdot10^5$, and the sum of $d$ over all test cases does not exceed $2\cdot10^5$.
-----Output-----
For each test case, output one of the following.
If no such $k$ exists, output Impossible.
If $k$ can be arbitrarily large, output Infinity.
Otherwise, output a single integer β the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days.
Please note, the checker is case-sensitive, and you should output strings exactly as they are given.
-----Examples-----
Input
6
2 5 4
1 2
2 20 10
100 10
3 100 3
7 2 6
4 20 3
4 5 6 7
4 100000000000 2022
8217734 927368 26389746 627896974
2 20 4
5 1
Output
2
Infinity
Impossible
1
12
0
-----Note-----
In the first test case, one way to earn $5$ coins over $4$ days with $k=2$ is as follows:
Day 1: do quest 2, and earn $2$ coins.
Day 2: do quest 1, and earn $1$ coin.
Day 3: do nothing.
Day 4: do quest 2, and earn $2$ coins.
In total, we earned $2+1+2=5$ coins.
In the second test case, we can make over $20$ coins on the first day itself by doing the first quest to earn $100$ coins, so the value of $k$ can be arbitrarily large, since we never need to do another quest.
In the third test case, no matter what we do, we can't earn $100$ coins over $3$ days.
|
def binp(b, m, c, y):
if b[c] >= m and b[c - 1] < m:
return c
elif b[c] > m:
return binp(b, m, c - y, max(y // 2, 1))
elif b[c] < m:
return binp(b, m, c + y, max(y // 2, 1))
for _ in range(int(input())):
n, c, d = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = -1
s = 0
b = [0]
I = -1
i = 0
while True:
if i < n:
s += a[i]
b.append(s)
w = c // s * (i + 1) + (
binp(b, c % s, len(b) // 2, max(len(b) // 2 // 2, 1))
if c % s > 0
else 0
)
elif c % s == 0:
w = (c // s - 1) * (i + 1) + len(b) - 1
else:
w = c // s * (i + 1) + (
binp(b, c % s, len(b) // 2, max(len(b) // 2 // 2, 1))
if c % s > 0
else 0
)
if c <= s and i + 1 <= d:
I = 1
break
if w <= d:
ans = i
else:
break
i += 1
if I == 1:
print("Infinity")
elif ans > -1:
print(ans)
else:
print("Impossible")
|
FUNC_DEF IF VAR VAR VAR VAR BIN_OP VAR NUMBER VAR RETURN VAR IF VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR RETURN FUNC_CALL VAR VAR VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER NUMBER IF BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER NUMBER IF VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
|
There are $n$ quests. If you complete the $i$-th quest, you will gain $a_i$ coins. You can only complete at most one quest per day. However, once you complete a quest, you cannot do the same quest again for $k$ days. (For example, if $k=2$ and you do quest $1$ on day $1$, then you cannot do it on day $2$ or $3$, but you can do it again on day $4$.)
You are given two integers $c$ and $d$. Find the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days. If no such $k$ exists, output Impossible. If $k$ can be arbitrarily large, output Infinity.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 10^4$) β the number of test cases. The description of the test cases follows.
The first line of each test case contains three integers $n,c,d$ ($2 \leq n \leq 2\cdot10^5$; $1 \leq c \leq 10^{16}$; $1 \leq d \leq 2\cdot10^5$) β the number of quests, the number of coins you need, and the number of days.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^9$) β the rewards for the quests.
The sum of $n$ over all test cases does not exceed $2\cdot10^5$, and the sum of $d$ over all test cases does not exceed $2\cdot10^5$.
-----Output-----
For each test case, output one of the following.
If no such $k$ exists, output Impossible.
If $k$ can be arbitrarily large, output Infinity.
Otherwise, output a single integer β the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days.
Please note, the checker is case-sensitive, and you should output strings exactly as they are given.
-----Examples-----
Input
6
2 5 4
1 2
2 20 10
100 10
3 100 3
7 2 6
4 20 3
4 5 6 7
4 100000000000 2022
8217734 927368 26389746 627896974
2 20 4
5 1
Output
2
Infinity
Impossible
1
12
0
-----Note-----
In the first test case, one way to earn $5$ coins over $4$ days with $k=2$ is as follows:
Day 1: do quest 2, and earn $2$ coins.
Day 2: do quest 1, and earn $1$ coin.
Day 3: do nothing.
Day 4: do quest 2, and earn $2$ coins.
In total, we earned $2+1+2=5$ coins.
In the second test case, we can make over $20$ coins on the first day itself by doing the first quest to earn $100$ coins, so the value of $k$ can be arbitrarily large, since we never need to do another quest.
In the third test case, no matter what we do, we can't earn $100$ coins over $3$ days.
|
def binary_search(a, days, cnt):
a = a
days = days
cnt = cnt
l = 0
r = days
while r - l != 1:
m = (r + l) // 2
temp = sum(a[0:m]) * (days // m) + sum(a[0 : days - m * (days // m)])
if temp >= cnt:
l = m
else:
r = m
return l - 1
t = int(input())
for p in range(t):
n, cnt, days = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
x = sum(a[0:days])
if x >= cnt:
print("Infinity")
elif a[0] * days < cnt:
print("Impossible")
else:
print(binary_search(a, days, cnt))
|
FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR BIN_OP VAR VAR FUNC_CALL VAR VAR NUMBER BIN_OP VAR BIN_OP VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR
|
There are $n$ quests. If you complete the $i$-th quest, you will gain $a_i$ coins. You can only complete at most one quest per day. However, once you complete a quest, you cannot do the same quest again for $k$ days. (For example, if $k=2$ and you do quest $1$ on day $1$, then you cannot do it on day $2$ or $3$, but you can do it again on day $4$.)
You are given two integers $c$ and $d$. Find the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days. If no such $k$ exists, output Impossible. If $k$ can be arbitrarily large, output Infinity.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 10^4$) β the number of test cases. The description of the test cases follows.
The first line of each test case contains three integers $n,c,d$ ($2 \leq n \leq 2\cdot10^5$; $1 \leq c \leq 10^{16}$; $1 \leq d \leq 2\cdot10^5$) β the number of quests, the number of coins you need, and the number of days.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^9$) β the rewards for the quests.
The sum of $n$ over all test cases does not exceed $2\cdot10^5$, and the sum of $d$ over all test cases does not exceed $2\cdot10^5$.
-----Output-----
For each test case, output one of the following.
If no such $k$ exists, output Impossible.
If $k$ can be arbitrarily large, output Infinity.
Otherwise, output a single integer β the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days.
Please note, the checker is case-sensitive, and you should output strings exactly as they are given.
-----Examples-----
Input
6
2 5 4
1 2
2 20 10
100 10
3 100 3
7 2 6
4 20 3
4 5 6 7
4 100000000000 2022
8217734 927368 26389746 627896974
2 20 4
5 1
Output
2
Infinity
Impossible
1
12
0
-----Note-----
In the first test case, one way to earn $5$ coins over $4$ days with $k=2$ is as follows:
Day 1: do quest 2, and earn $2$ coins.
Day 2: do quest 1, and earn $1$ coin.
Day 3: do nothing.
Day 4: do quest 2, and earn $2$ coins.
In total, we earned $2+1+2=5$ coins.
In the second test case, we can make over $20$ coins on the first day itself by doing the first quest to earn $100$ coins, so the value of $k$ can be arbitrarily large, since we never need to do another quest.
In the third test case, no matter what we do, we can't earn $100$ coins over $3$ days.
|
from itertools import accumulate
test = int(input())
while test:
n, c, d = map(int, input().split())
a = [int(x) for x in input().split()]
a.sort(reverse=True)
pre_sum = list(accumulate(a))
low = -1
high = d + 1
while low < high:
mid = low + high + 1 >> 1
curr_coins = 0
for i in range(d):
ind = i % (mid + 1)
if ind < n:
curr_coins += a[ind]
if curr_coins >= c:
low = mid
else:
high = mid - 1
if low == -1:
print("Impossible")
elif low == d + 1:
print("Infinity")
else:
print(low)
test -= 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR NUMBER
|
There are $n$ quests. If you complete the $i$-th quest, you will gain $a_i$ coins. You can only complete at most one quest per day. However, once you complete a quest, you cannot do the same quest again for $k$ days. (For example, if $k=2$ and you do quest $1$ on day $1$, then you cannot do it on day $2$ or $3$, but you can do it again on day $4$.)
You are given two integers $c$ and $d$. Find the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days. If no such $k$ exists, output Impossible. If $k$ can be arbitrarily large, output Infinity.
-----Input-----
The input consists of multiple test cases. The first line contains an integer $t$ ($1 \leq t \leq 10^4$) β the number of test cases. The description of the test cases follows.
The first line of each test case contains three integers $n,c,d$ ($2 \leq n \leq 2\cdot10^5$; $1 \leq c \leq 10^{16}$; $1 \leq d \leq 2\cdot10^5$) β the number of quests, the number of coins you need, and the number of days.
The second line of each test case contains $n$ integers $a_1, a_2, \dots, a_n$ ($1 \leq a_i \leq 10^9$) β the rewards for the quests.
The sum of $n$ over all test cases does not exceed $2\cdot10^5$, and the sum of $d$ over all test cases does not exceed $2\cdot10^5$.
-----Output-----
For each test case, output one of the following.
If no such $k$ exists, output Impossible.
If $k$ can be arbitrarily large, output Infinity.
Otherwise, output a single integer β the maximum value of $k$ such that you can gain at least $c$ coins over $d$ days.
Please note, the checker is case-sensitive, and you should output strings exactly as they are given.
-----Examples-----
Input
6
2 5 4
1 2
2 20 10
100 10
3 100 3
7 2 6
4 20 3
4 5 6 7
4 100000000000 2022
8217734 927368 26389746 627896974
2 20 4
5 1
Output
2
Infinity
Impossible
1
12
0
-----Note-----
In the first test case, one way to earn $5$ coins over $4$ days with $k=2$ is as follows:
Day 1: do quest 2, and earn $2$ coins.
Day 2: do quest 1, and earn $1$ coin.
Day 3: do nothing.
Day 4: do quest 2, and earn $2$ coins.
In total, we earned $2+1+2=5$ coins.
In the second test case, we can make over $20$ coins on the first day itself by doing the first quest to earn $100$ coins, so the value of $k$ can be arbitrarily large, since we never need to do another quest.
In the third test case, no matter what we do, we can't earn $100$ coins over $3$ days.
|
t = int(input(""))
aas = [0] * t
for j in range(t):
ncd = input("").split(" ")
n = int(ncd[0])
c = int(ncd[1])
d = int(ncd[2])
y = input("").split(" ")
y = sorted([int(z) for z in y])[::-1]
y += [0] * d
z = [0] * (n + 1 + d)
for i in range(n + d):
z[i + 1] = z[i] + y[i]
if y[0] * d < c:
aas[j] = "Impossible"
elif z[d] >= c:
aas[j] = "Infinity"
else:
kmin = 1
kmax = d
while kmin + 1 < kmax:
kmed = (kmin + kmax) // 2
q = d // kmed
r = d % kmed
prof = q * z[kmed] + z[r]
if prof >= c:
kmin = kmed
else:
kmax = kmed
aas[j] = kmin - 1
for a in aas:
print(a)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR STRING ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR NUMBER VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR IF BIN_OP VAR NUMBER VAR VAR ASSIGN VAR VAR STRING IF VAR VAR VAR ASSIGN VAR VAR STRING ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR
|
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero.
Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating.
What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible".
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 200 000).
The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 β€ c_{i} β€ 100, 1 β€ d_{i} β€ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest.
-----Output-----
If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests.
-----Examples-----
Input
3
-7 1
5 2
8 2
Output
1907
Input
2
57 1
22 2
Output
Impossible
Input
1
-5 1
Output
Infinity
Input
4
27 2
13 1
-50 1
8 2
Output
1897
-----Note-----
In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907.
In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
|
import sys
def change_rating(div, change):
if div == 1:
ranged[0] = max(ranged[0], 1900)
else:
ranged[1] = min(ranged[1], 1899)
if ranged[0] > ranged[1]:
return False
ranged[0] += change
ranged[1] += change
return True
def get_max_cur(start):
t = start
m = start
for change in reversed(changes):
m = max(m, start - change)
start -= change
if m >= inf:
return m
return t
n = int(input())
inf = sys.maxsize * 2000
ranged = [-inf, inf]
changes = []
for _ in range(n):
chnage, div = list(map(int, input().split()))
if not change_rating(div, chnage):
print("Impossible")
return
changes.append(chnage)
max_r = get_max_cur(ranged[1])
if max_r >= inf:
print("Infinity")
else:
print(max_r)
|
IMPORT FUNC_DEF IF VAR NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER FUNC_CALL VAR VAR NUMBER NUMBER IF VAR NUMBER VAR NUMBER RETURN NUMBER VAR NUMBER VAR VAR NUMBER VAR RETURN NUMBER FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR VAR IF VAR VAR RETURN VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
|
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero.
Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating.
What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible".
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 200 000).
The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 β€ c_{i} β€ 100, 1 β€ d_{i} β€ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest.
-----Output-----
If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests.
-----Examples-----
Input
3
-7 1
5 2
8 2
Output
1907
Input
2
57 1
22 2
Output
Impossible
Input
1
-5 1
Output
Infinity
Input
4
27 2
13 1
-50 1
8 2
Output
1897
-----Note-----
In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907.
In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
|
n = int(input())
l = -1000000000000000.0
r = 1000000000000000.0
c = list(range(n))
d = list(range(n))
s = list(range(n))
for i in range(n):
c[i], d[i] = map(int, input().split())
if i > 0:
s[i] = s[i - 1] + c[i - 1]
if d[i] == 1:
l = max(1900 - s[i], l)
else:
r = min(1899 - s[i], r)
if r < l:
print("Impossible")
quit()
if d[0] == 1:
l = max(1900, l)
else:
r = min(1899, r)
if r < l:
print("Impossible")
elif r == 1000000000000000.0:
print("Infinity")
else:
print(r + s[n - 1] + c[n - 1])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER
|
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero.
Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating.
What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible".
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 200 000).
The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 β€ c_{i} β€ 100, 1 β€ d_{i} β€ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest.
-----Output-----
If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests.
-----Examples-----
Input
3
-7 1
5 2
8 2
Output
1907
Input
2
57 1
22 2
Output
Impossible
Input
1
-5 1
Output
Infinity
Input
4
27 2
13 1
-50 1
8 2
Output
1897
-----Note-----
In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907.
In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
|
Q = int(input())
change = 0
D1 = []
D2 = []
check1 = 0
check2 = 0
change, start = list(map(int, input().strip().split(" ")))
pred = start
for i in range(1, Q):
c, d = list(map(int, input().strip().split(" ")))
if i == 1:
if d == 1:
MIN1 = change
D1 = [MIN1]
else:
MAX2 = change
D2 = [MAX2]
change += c
elif d == 1:
if len(D1) == 0:
MIN1 = change
D1 = [change]
change += c
else:
if MIN1 > change:
MIN1 = change
D1 = [change]
change += c
elif len(D2) == 0:
MAX2 = change
D2 = [change]
change += c
else:
if MAX2 < change:
MAX2 = change
D2 = [change]
change += c
if Q == 1:
if start == 1:
print("Infinity")
else:
print(1899 + change)
elif start == 1:
if D2 == []:
print("Infinity")
else:
if D1 == []:
change1 = 0
else:
change1 = min(min(D1), 0)
change2 = max(D2)
if max(1900, 1900 - change1) <= 1899 - change2:
print(1899 - change2 + change)
else:
print("Impossible")
elif D1 == []:
temp = change
if D2 == []:
temp2 = 0
else:
temp2 = max(max(D2), 0)
if temp2 > 0:
ans = 1899 - temp2 + change
print(ans)
else:
ans = 1899 + change
print(ans)
else:
if D1 == []:
change1 = 0
elif D1 == 0:
change1 = 0
else:
change1 = min(D1)
if D2 == []:
change2 = 0
else:
change2 = max(D2)
if 1900 - change1 <= min(1899 - change2, 1899):
print(min(1899 - change2, 1899) + change)
else:
print("Impossible")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST VAR ASSIGN VAR VAR ASSIGN VAR LIST VAR VAR VAR IF VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST VAR VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST VAR VAR VAR IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP NUMBER VAR IF VAR NUMBER IF VAR LIST EXPR FUNC_CALL VAR STRING IF VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR NUMBER BIN_OP NUMBER VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR STRING IF VAR LIST ASSIGN VAR VAR IF VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR VAR IF VAR LIST ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR LIST ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF BIN_OP NUMBER VAR FUNC_CALL VAR BIN_OP NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP NUMBER VAR NUMBER VAR EXPR FUNC_CALL VAR STRING
|
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero.
Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating.
What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible".
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 200 000).
The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 β€ c_{i} β€ 100, 1 β€ d_{i} β€ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest.
-----Output-----
If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests.
-----Examples-----
Input
3
-7 1
5 2
8 2
Output
1907
Input
2
57 1
22 2
Output
Impossible
Input
1
-5 1
Output
Infinity
Input
4
27 2
13 1
-50 1
8 2
Output
1897
-----Note-----
In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907.
In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
|
n = int(input())
INF = 10**9
emax, emin = INF, -INF
for _ in range(n):
c, d = map(int, input().split())
if d == 1:
emin = max(emin, 1900)
elif d == 2:
emax = min(emax, 1899)
emin += c
emax += c
if emin > emax:
print("Impossible")
elif emax >= INF / 2:
print("Infinity")
else:
print(emax)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
|
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero.
Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating.
What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible".
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 200 000).
The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 β€ c_{i} β€ 100, 1 β€ d_{i} β€ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest.
-----Output-----
If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests.
-----Examples-----
Input
3
-7 1
5 2
8 2
Output
1907
Input
2
57 1
22 2
Output
Impossible
Input
1
-5 1
Output
Infinity
Input
4
27 2
13 1
-50 1
8 2
Output
1897
-----Note-----
In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907.
In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
|
n = int(input())
r = 0
xmin = -(10**8)
xmax = 10**8
infin = 1
c, d = [int(t) for t in input().split(" ")]
if d == 2:
xmax = 1899
infin = 0
else:
xmin = 1900
for i in range(n - 1):
c0 = c
d0 = d
c, d = [int(t) for t in input().split(" ")]
xmax += c0
xmin += c0
if d == 2:
xmax = min(xmax, 1899)
infin = 0
else:
xmin = max(xmin, 1900)
if c0 == 0 and d != d0:
r = -1
if xmax < xmin:
r = -1
if r == -1:
print("Impossible")
elif xmax >= 10**8 or infin == 1:
print("Infinity")
else:
print(xmax + c)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING VAR VAR VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR BIN_OP NUMBER NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero.
Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating.
What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible".
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 200 000).
The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 β€ c_{i} β€ 100, 1 β€ d_{i} β€ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest.
-----Output-----
If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests.
-----Examples-----
Input
3
-7 1
5 2
8 2
Output
1907
Input
2
57 1
22 2
Output
Impossible
Input
1
-5 1
Output
Infinity
Input
4
27 2
13 1
-50 1
8 2
Output
1897
-----Note-----
In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907.
In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
|
INF = float("inf")
n = int(input())
dp1 = [(0) for _ in range(n + 1)]
dp2 = [(0) for _ in range(n + 1)]
d = list()
c = list()
for _ in range(n):
x, y = map(int, input().split())
c.append(x)
d.append(y)
if d[0] == 1:
dp1[0] = 1900
dp2[0] = INF
else:
dp1[0] = -INF
dp2[0] = 1899
impossible = False
for i in range(1, n):
if d[i - 1] == 1 and d[i] == 1:
dp1[i] = max(1900, dp1[i - 1] + c[i - 1])
dp2[i] = dp2[i - 1] + c[i - 1]
elif d[i - 1] == 2 and d[i] == 2:
dp1[i] = dp1[i - 1] + c[i - 1]
dp2[i] = min(1899, dp2[i - 1] + c[i - 1])
elif d[i - 1] == 1 and d[i] == 2:
dp1[i] = max(1899 + c[i - 1], dp1[i - 1] + c[i - 1])
dp2[i] = min(1899, dp2[i - 1] + c[i - 1])
elif d[i - 1] == 2 and d[i] == 1:
dp1[i] = max(1900, dp1[i - 1] + c[i - 1])
dp2[i] = dp2[i - 1] + c[i - 1]
if dp1[i] > dp2[i]:
impossible = True
dp2[n] = dp2[n - 1] + c[n - 1]
if impossible:
print("Impossible")
elif dp2[n] == INF:
print("Infinity")
else:
print(dp2[n])
|
ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER VAR ASSIGN VAR NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER NUMBER VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING IF VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR VAR
|
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero.
Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating.
What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible".
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 200 000).
The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 β€ c_{i} β€ 100, 1 β€ d_{i} β€ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest.
-----Output-----
If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests.
-----Examples-----
Input
3
-7 1
5 2
8 2
Output
1907
Input
2
57 1
22 2
Output
Impossible
Input
1
-5 1
Output
Infinity
Input
4
27 2
13 1
-50 1
8 2
Output
1897
-----Note-----
In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907.
In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
|
n = int(input())
dirs = []
for x in range(0, n):
line = input().split()
dirs.append([int(line[0]), int(line[1])])
pre = 0
L = -200000000
R = 200000000
for dir in dirs:
if dir[1] == 1:
L = max(L, 1900 - pre)
else:
R = min(R, 1899 - pre)
pre = pre + dir[0]
if L > R:
print("Impossible")
elif L <= R and R == 200000000:
print("Infinity")
else:
print(pre + R)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR LIST FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero.
Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating.
What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible".
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 200 000).
The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 β€ c_{i} β€ 100, 1 β€ d_{i} β€ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest.
-----Output-----
If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests.
-----Examples-----
Input
3
-7 1
5 2
8 2
Output
1907
Input
2
57 1
22 2
Output
Impossible
Input
1
-5 1
Output
Infinity
Input
4
27 2
13 1
-50 1
8 2
Output
1897
-----Note-----
In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907.
In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
|
n = int(input())
c = [(0) for i in range(n)]
c[0], d = map(int, input().split())
INF = 1000000000.0
a = -INF
b = INF
if d == 1:
a = 1900
else:
b = 1899
s = 0
for i in range(1, n):
c[i], d = map(int, input().split())
s += c[i - 1]
if d == 1:
a = max(1900 - s, a)
else:
b = min(1899 - s, b)
s += c[n - 1]
if b == INF:
print("Infinity")
elif a > b:
print("Impossible")
else:
print(b + s)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero.
Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating.
What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible".
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 200 000).
The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 β€ c_{i} β€ 100, 1 β€ d_{i} β€ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest.
-----Output-----
If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests.
-----Examples-----
Input
3
-7 1
5 2
8 2
Output
1907
Input
2
57 1
22 2
Output
Impossible
Input
1
-5 1
Output
Infinity
Input
4
27 2
13 1
-50 1
8 2
Output
1897
-----Note-----
In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907.
In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
|
n = int(input())
rounds = [[*map(int, input().split())] for _ in range(n)]
ans = -1
def check(m):
d = int()
for i, j in rounds:
d = 2 if m < 1900 else 1
if d != j:
if d == 2:
return 0
else:
return -1
m += i
global ans
ans = m
return 1
def binsearch(l, r):
while l < r:
m = (l + r + 1) // 2
if check(m) == -1:
r = m - 1
elif check(m) == 0:
l = m + 1
else:
l = m
return l
if all(i[1] == 1 for i in rounds):
print("Infinity")
else:
v = binsearch(int(-100000000.0), int(100000000.0))
print(ans if check(v) == 1 else "Impossible")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR VAR VAR ASSIGN VAR VAR NUMBER NUMBER NUMBER IF VAR VAR IF VAR NUMBER RETURN NUMBER RETURN NUMBER VAR VAR ASSIGN VAR VAR RETURN NUMBER FUNC_DEF WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR IF FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR STRING
|
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero.
Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating.
What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible".
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 200 000).
The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 β€ c_{i} β€ 100, 1 β€ d_{i} β€ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest.
-----Output-----
If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests.
-----Examples-----
Input
3
-7 1
5 2
8 2
Output
1907
Input
2
57 1
22 2
Output
Impossible
Input
1
-5 1
Output
Infinity
Input
4
27 2
13 1
-50 1
8 2
Output
1897
-----Note-----
In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907.
In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
|
def main():
(n,) = read()
mn, mx = -(10**18), 10**18
for _ in range(n):
c, d = read()
if d == 1:
mn = max(mn, 1900)
elif d == 2:
mx = min(mx, 1899)
mn += c
mx += c
if mn > mx:
print("Impossible")
return
if mx > 10**17:
print("Infinity")
return
print(mx)
def read(callback=int):
return list(map(callback, input().strip().split()))
def write(value, end="\n"):
if value is None:
return
try:
value = " ".join(map(str, value))
except:
pass
print(value, end=end)
write(main())
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING RETURN IF VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR STRING RETURN EXPR FUNC_CALL VAR VAR FUNC_DEF VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF STRING IF VAR NONE RETURN ASSIGN VAR FUNC_CALL STRING FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
|
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero.
Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating.
What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible".
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 200 000).
The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 β€ c_{i} β€ 100, 1 β€ d_{i} β€ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest.
-----Output-----
If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests.
-----Examples-----
Input
3
-7 1
5 2
8 2
Output
1907
Input
2
57 1
22 2
Output
Impossible
Input
1
-5 1
Output
Infinity
Input
4
27 2
13 1
-50 1
8 2
Output
1897
-----Note-----
In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907.
In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
|
n = int(input())
score = 0
div2_max = -100000000
only_div1 = 1
div = 0
change = 0
contest = [(0, 0)] * (n + 5)
for i in range(1, n + 1):
c, d = map(int, input().split())
only_div1 &= d == 1
if div == 1 and d == 2 and change >= 0:
print("Impossible")
exit()
if div == 2 and d == 1 and change <= 0:
print("Impossible")
exit()
contest[i - 1] = d, score
if d == 2:
div2_max = max(div2_max, score)
score += c
change = c
div = d
for i in range(n):
if contest[i][0] == 2 and contest[i][1] > div2_max:
print("Impossible")
exit()
if contest[i][0] == 1 and contest[i][1] <= div2_max:
print("Impossible")
exit()
if only_div1:
print("Infinity")
else:
print(score + (1899 - div2_max))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR VAR NUMBER NUMBER VAR VAR NUMBER VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP NUMBER VAR
|
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero.
Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating.
What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible".
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 200 000).
The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 β€ c_{i} β€ 100, 1 β€ d_{i} β€ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest.
-----Output-----
If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests.
-----Examples-----
Input
3
-7 1
5 2
8 2
Output
1907
Input
2
57 1
22 2
Output
Impossible
Input
1
-5 1
Output
Infinity
Input
4
27 2
13 1
-50 1
8 2
Output
1897
-----Note-----
In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907.
In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
|
n = int(input())
l = [[0, 0] for i in range(n + 1)]
for i in range(n):
if i == 0:
l.append([0, 0])
a, b = list(map(int, input().split()))
l[i + 1][0] += l[i][0] + a
l[i][1] = b
def search(x):
for i in range(n):
if l[i][1] == 2 and x > 1899 - l[i][0]:
return "s"
if l[i][1] == 1 and x < 1900 - l[i][0]:
return "b"
return "ok"
uk1 = -1000000000
uk2 = 1000000000
mb = False
for i in range(n):
if l[i][1] == 2:
mb = True
if not mb:
print("Infinity")
exit()
while uk2 - uk1 > 1:
mac = (uk2 + uk1) // 2
if search(mac) == "s":
uk2 = mac
else:
uk1 = mac
if search(uk1) == "ok":
print(uk1 + l[-2][0])
else:
print("Impossible")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR LIST NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER BIN_OP VAR VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR FUNC_DEF FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER NUMBER VAR BIN_OP NUMBER VAR VAR NUMBER RETURN STRING IF VAR VAR NUMBER NUMBER VAR BIN_OP NUMBER VAR VAR NUMBER RETURN STRING RETURN STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR STRING ASSIGN VAR VAR ASSIGN VAR VAR IF FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING
|
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero.
Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating.
What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible".
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 200 000).
The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 β€ c_{i} β€ 100, 1 β€ d_{i} β€ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest.
-----Output-----
If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests.
-----Examples-----
Input
3
-7 1
5 2
8 2
Output
1907
Input
2
57 1
22 2
Output
Impossible
Input
1
-5 1
Output
Infinity
Input
4
27 2
13 1
-50 1
8 2
Output
1897
-----Note-----
In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907.
In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
|
I = lambda: list(map(int, input().split()))
n = I()[0]
c, d = [([0] * n) for _ in range(2)]
for i in range(n):
_c, _d = I()
c[i] = _c
d[i] = _d
lb, ub, change = -1e100, 1e100, 0
for i in range(n)[::-1]:
change -= c[i]
if d[i] == 1:
lb = max(lb, 1900 - change)
else:
ub = min(ub, 1899 - change)
if lb > ub:
print("Impossible")
break
if ub == 1e100:
print("Infinity")
elif lb <= ub:
print(ub)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR BIN_OP LIST NUMBER VAR VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR VAR
|
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero.
Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating.
What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible".
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 200 000).
The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 β€ c_{i} β€ 100, 1 β€ d_{i} β€ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest.
-----Output-----
If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests.
-----Examples-----
Input
3
-7 1
5 2
8 2
Output
1907
Input
2
57 1
22 2
Output
Impossible
Input
1
-5 1
Output
Infinity
Input
4
27 2
13 1
-50 1
8 2
Output
1897
-----Note-----
In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907.
In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
|
n = int(input())
con = []
for i in range(n):
r, d = map(int, input().split())
con.append((r, d))
if all(c[1] == 1 for c in con):
print("Infinity")
exit()
tot = 0
if con[0][1] == 1:
s, f = 1900, 10**19
else:
s, f = -(10**19), 1899
for i in range(n - 1):
tot += con[i][0]
aft = con[i + 1][1]
if aft == 2:
f = min(f, 1899 - tot)
else:
s = max(s, 1900 - tot)
if s > f:
print("Impossible")
else:
print(f + tot + con[-1][0])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR VAR IF FUNC_CALL VAR VAR NUMBER NUMBER VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER IF VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR VAR BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER
|
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero.
Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating.
What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible".
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 200 000).
The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 β€ c_{i} β€ 100, 1 β€ d_{i} β€ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest.
-----Output-----
If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests.
-----Examples-----
Input
3
-7 1
5 2
8 2
Output
1907
Input
2
57 1
22 2
Output
Impossible
Input
1
-5 1
Output
Infinity
Input
4
27 2
13 1
-50 1
8 2
Output
1897
-----Note-----
In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907.
In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
|
n = int(input())
up = 0
wasup = 0
down = 0
wasdown = 0
for i in range(n):
c, d = [int(i) for i in input().split()]
if d == 1:
if not wasdown:
down = 1900
wasdown = 1
down = max(down, 1900)
down += c
if wasup:
up += c
if d == 2:
if not wasup:
up = 1899
wasup = 1
up = min(up, 1899)
up += c
if wasdown:
down += c
if wasup and wasdown:
if up < down:
print("Impossible")
break
else:
if wasup:
print(up)
else:
print("Infinity")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR IF VAR VAR VAR IF VAR NUMBER IF VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR IF VAR VAR VAR IF VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
|
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero.
Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating.
What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible".
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 200 000).
The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 β€ c_{i} β€ 100, 1 β€ d_{i} β€ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest.
-----Output-----
If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests.
-----Examples-----
Input
3
-7 1
5 2
8 2
Output
1907
Input
2
57 1
22 2
Output
Impossible
Input
1
-5 1
Output
Infinity
Input
4
27 2
13 1
-50 1
8 2
Output
1897
-----Note-----
In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907.
In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
|
num_contests = int(input())
rating = 0
upper_bound = None
lower_bound = None
for contest_num in range(num_contests):
ci, di = map(int, input().split())
if di == 1:
if upper_bound is None or rating < upper_bound:
upper_bound = rating
else:
assert di == 2
if lower_bound is None or rating > lower_bound:
lower_bound = rating
rating += ci
if lower_bound is None:
print("Infinity")
elif upper_bound is not None and lower_bound >= upper_bound:
print("Impossible")
else:
print(rating - (lower_bound + 1) + 1900)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NONE ASSIGN VAR NONE FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NONE VAR VAR ASSIGN VAR VAR VAR NUMBER IF VAR NONE VAR VAR ASSIGN VAR VAR VAR VAR IF VAR NONE EXPR FUNC_CALL VAR STRING IF VAR NONE VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER
|
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero.
Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating.
What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible".
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 200 000).
The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 β€ c_{i} β€ 100, 1 β€ d_{i} β€ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest.
-----Output-----
If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests.
-----Examples-----
Input
3
-7 1
5 2
8 2
Output
1907
Input
2
57 1
22 2
Output
Impossible
Input
1
-5 1
Output
Infinity
Input
4
27 2
13 1
-50 1
8 2
Output
1897
-----Note-----
In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907.
In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
|
s = 0
a = b = ""
for i in range(int(input())):
c, d = map(int, input().split())
if d == 1:
a = min(a, s) if a != "" else s
else:
b = max(b, s) if b != "" else s
s += c
print(
"Infinity" if b == "" else "Impossible" if a != "" and a - b < 1 else 1899 - b + s
)
|
ASSIGN VAR NUMBER ASSIGN VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR VAR STRING FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR STRING FUNC_CALL VAR VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR STRING STRING VAR STRING BIN_OP VAR VAR NUMBER STRING BIN_OP BIN_OP NUMBER VAR VAR
|
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero.
Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating.
What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible".
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 200 000).
The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 β€ c_{i} β€ 100, 1 β€ d_{i} β€ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest.
-----Output-----
If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests.
-----Examples-----
Input
3
-7 1
5 2
8 2
Output
1907
Input
2
57 1
22 2
Output
Impossible
Input
1
-5 1
Output
Infinity
Input
4
27 2
13 1
-50 1
8 2
Output
1897
-----Note-----
In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907.
In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
|
n = int(input())
ratings = []
divs = []
for i in range(n):
a, b = map(int, input().split())
ratings.append(a)
divs.append(b)
curmax = float("inf")
curmin = float("-inf")
if n == 1:
if divs[0] == 1:
print("Infinity")
else:
print(1899 + ratings[0])
else:
for k in range(n - 1):
st = divs[k]
fin = divs[k + 1]
change = ratings[k]
if st == 1 and fin == 2:
if change >= 0:
print("Impossible")
break
curmax = min(curmax + change, 1899)
curmin = max(curmin + change, 1900 + change)
elif st == 2 and fin == 2:
curmax = min(curmax + change, 1899, 1899 + change)
curmin += change
elif st == 1 and fin == 1:
curmin = max(curmin + change, 1900, 1900 + change)
curmax += change
elif st == 2 and fin == 1:
if change <= 0:
print("Impossible")
break
curmax = min(curmax + change, 1899 + change)
curmin = max(curmin + change, 1900)
else:
if curmax == float("inf"):
print("Infinity")
elif curmin > curmax:
print("Impossible")
else:
print(curmax + ratings[-1])
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING IF VAR NUMBER IF VAR NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP NUMBER VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP NUMBER VAR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER IF VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR NUMBER
|
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero.
Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating.
What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible".
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 200 000).
The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 β€ c_{i} β€ 100, 1 β€ d_{i} β€ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest.
-----Output-----
If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests.
-----Examples-----
Input
3
-7 1
5 2
8 2
Output
1907
Input
2
57 1
22 2
Output
Impossible
Input
1
-5 1
Output
Infinity
Input
4
27 2
13 1
-50 1
8 2
Output
1897
-----Note-----
In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907.
In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
|
import sys
def input():
return sys.stdin.readline().strip()
def iinput():
return int(input())
def minput():
return map(int, input().split())
def listinput():
return list(map(int, input().split()))
rate = 0
a = 10**9
b = -a
for _ in range(iinput()):
r, d = minput()
if d == 1:
b = max(b, 1900 - rate)
else:
a = min(a, 1899 - rate)
rate += r
if a >= 10**9:
print("Infinity")
elif a < b:
print("Impossible")
else:
print(a + rate)
|
IMPORT FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR VAR VAR IF VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR STRING IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero.
Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating.
What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible".
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 200 000).
The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 β€ c_{i} β€ 100, 1 β€ d_{i} β€ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest.
-----Output-----
If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests.
-----Examples-----
Input
3
-7 1
5 2
8 2
Output
1907
Input
2
57 1
22 2
Output
Impossible
Input
1
-5 1
Output
Infinity
Input
4
27 2
13 1
-50 1
8 2
Output
1897
-----Note-----
In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907.
In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
|
def ri():
return map(int, input().split())
n = int(input())
maxr = 100 * 200000 + 10**9
minr = -maxr
INF = maxr
if n == 1:
c, d = ri()
if d == 1:
print("Infinity")
else:
print(1899 + c)
exit()
csum = 0
r = 0
c, d = ri()
cprev = c
dprev = d
if d == 1:
r = maxr
minr = 1900
else:
r = 1899
maxr = 1899
for i in range(1, n):
c, d = ri()
csum += cprev
r += cprev
if dprev == 1 and d == 1:
if cprev >= 0:
pass
elif r < 1900:
print("Impossible")
exit()
else:
minr = max(minr, 1900 - csum)
if maxr < minr:
print("Impossible")
exit()
if dprev == 1 and d == 2:
if cprev >= 0:
print("Impossible")
exit()
elif r >= 1900:
maxr = 1899 - csum
if maxr < minr:
print("Impossible")
exit()
r = 1899
else:
maxr = min(maxr, 1899 - csum)
if maxr < minr:
print("Impossible")
exit()
if dprev == 2 and d == 1:
if cprev <= 0:
print("Impossible")
exit()
elif r < 1900:
print("Impossible")
exit()
else:
minr = max(minr, 1900 - csum)
if maxr < minr:
print("Impossible")
exit()
if dprev == 2 and d == 2:
if cprev > 0:
if r >= 1900:
maxr = 1899 - csum
r = 1899
if maxr < minr:
print("Impossible")
exit()
else:
maxr = min(maxr, 1899 - csum)
if maxr < minr:
print("Impossible")
exit()
cprev = c
dprev = d
if maxr == INF:
print("Infinity")
else:
print(r + c)
|
FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero.
Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating.
What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible".
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 200 000).
The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 β€ c_{i} β€ 100, 1 β€ d_{i} β€ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest.
-----Output-----
If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests.
-----Examples-----
Input
3
-7 1
5 2
8 2
Output
1907
Input
2
57 1
22 2
Output
Impossible
Input
1
-5 1
Output
Infinity
Input
4
27 2
13 1
-50 1
8 2
Output
1897
-----Note-----
In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907.
In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
|
n = int(input())
max_r = float("inf")
min_r = -max_r
for i in range(0, n):
x, y = input().split()
x, y = int(x), int(y)
if i == 0:
if y == 1:
min_r = 1900
else:
max_r = 1899
else:
if y == 1 and max_r < 1900:
print("Impossible")
exit()
elif y == 1:
min_r = max(1900, min_r)
if y == 2 and min_r > 1899:
print("Impossible")
exit()
elif y == 2:
max_r = min(1899, max_r)
min_r = min_r + x
max_r = max_r + x
if max_r == float("inf"):
print("Infinity")
else:
print(max_r)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
|
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero.
Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating.
What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible".
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 200 000).
The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 β€ c_{i} β€ 100, 1 β€ d_{i} β€ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest.
-----Output-----
If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests.
-----Examples-----
Input
3
-7 1
5 2
8 2
Output
1907
Input
2
57 1
22 2
Output
Impossible
Input
1
-5 1
Output
Infinity
Input
4
27 2
13 1
-50 1
8 2
Output
1897
-----Note-----
In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907.
In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
|
n = int(input())
INF = 10**18
l = -INF
r = INF
s = 0
for _ in range(n):
c, d = map(int, input().split())
if d == 1 and l + s < 1900:
l = 1900 - s
if d == 2 and r + s >= 1900:
r = 1899 - s
s += c
if l < -INF:
l = -INF
if r > INF:
r = INF
if l > r:
print("Impossible")
elif r > 10**15:
print("Infinity")
else:
print(r + s)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR IF VAR NUMBER BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING IF VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR
|
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero.
Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating.
What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible".
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 200 000).
The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 β€ c_{i} β€ 100, 1 β€ d_{i} β€ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest.
-----Output-----
If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests.
-----Examples-----
Input
3
-7 1
5 2
8 2
Output
1907
Input
2
57 1
22 2
Output
Impossible
Input
1
-5 1
Output
Infinity
Input
4
27 2
13 1
-50 1
8 2
Output
1897
-----Note-----
In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907.
In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
|
n = int(input())
c, div = map(int, input().split())
if div == 1:
x = None
y = 1900
else:
x = 1899
y = None
proof = True
for i in range(n - 1):
if x != None:
x += c
if y != None:
y += c
c, div = map(int, input().split())
if div == 1:
if x != None and x < 1900:
proof = False
elif y == None:
y = 1900
else:
y = max(y, 1900)
elif y != None and y > 1899:
proof = False
elif x == None:
x = 1899
else:
x = min(x, 1899)
if proof:
if x == None:
print("Infinity")
else:
print(x + c)
else:
print("Impossible")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR NONE ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NONE ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NONE VAR VAR IF VAR NONE VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NONE VAR NUMBER ASSIGN VAR NUMBER IF VAR NONE ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NONE VAR NUMBER ASSIGN VAR NUMBER IF VAR NONE ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR IF VAR NONE EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR STRING
|
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero.
Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating.
What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible".
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 200 000).
The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 β€ c_{i} β€ 100, 1 β€ d_{i} β€ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest.
-----Output-----
If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests.
-----Examples-----
Input
3
-7 1
5 2
8 2
Output
1907
Input
2
57 1
22 2
Output
Impossible
Input
1
-5 1
Output
Infinity
Input
4
27 2
13 1
-50 1
8 2
Output
1897
-----Note-----
In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907.
In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
|
n = int(input())
c, d = [], []
for i in range(n):
ci, di = map(int, input().split())
c.append(ci), d.append(di)
s = [0] * (n + 1)
geq, leq = 0, 0
for i in reversed(range(n)):
s[i] = s[i + 1] + c[i]
if d[i] == 1:
if geq == 0:
g = s[i] + 1900
else:
g = max(g, s[i] + 1900)
geq += 1
elif d[i] == 2:
if leq == 0:
l = s[i] + 1899
else:
l = min(s[i] + 1899, l)
leq += 1
if leq == 0:
print("Infinity")
elif geq == 0 or g <= l:
print(l)
else:
print("Impossible")
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR IF VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR STRING IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR STRING
|
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero.
Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating.
What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible".
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 200 000).
The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 β€ c_{i} β€ 100, 1 β€ d_{i} β€ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest.
-----Output-----
If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests.
-----Examples-----
Input
3
-7 1
5 2
8 2
Output
1907
Input
2
57 1
22 2
Output
Impossible
Input
1
-5 1
Output
Infinity
Input
4
27 2
13 1
-50 1
8 2
Output
1897
-----Note-----
In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907.
In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
|
inf = float("inf")
def solve(c, d):
l = -inf
h = inf
for i in range(n):
if d[i] == 1:
l = max(1900, l)
else:
h = min(1899, h)
l += c[i]
h += c[i]
if h == inf:
return "Infinity"
if l > h:
return "Impossible"
return h
n = int(input())
c, d = [], []
for i in range(n):
ci, di = [int(item) for item in input().split()]
c.append(ci)
d.append(di)
print(solve(c, d))
|
ASSIGN VAR FUNC_CALL VAR STRING FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER VAR VAR VAR VAR VAR VAR VAR IF VAR VAR RETURN STRING IF VAR VAR RETURN STRING RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR LIST LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR
|
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero.
Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating.
What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible".
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 200 000).
The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 β€ c_{i} β€ 100, 1 β€ d_{i} β€ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest.
-----Output-----
If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests.
-----Examples-----
Input
3
-7 1
5 2
8 2
Output
1907
Input
2
57 1
22 2
Output
Impossible
Input
1
-5 1
Output
Infinity
Input
4
27 2
13 1
-50 1
8 2
Output
1897
-----Note-----
In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907.
In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
|
import sys
def Main(n):
mn, mx = -(10**18), 10**18
for _ in range(n):
c, d = map(int, input().split())
if d == 1:
mn = max(mn, 1900)
else:
mx = min(mx, 1899)
mn += c
mx += c
if mn > mx:
print("Impossible")
return 0
if mx > 10**17:
print("Infinity")
return 0
print(mx)
n = int(input())
Main(n)
|
IMPORT FUNC_DEF ASSIGN VAR VAR BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR STRING RETURN NUMBER IF VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR STRING RETURN NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
|
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero.
Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating.
What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible".
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 200 000).
The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 β€ c_{i} β€ 100, 1 β€ d_{i} β€ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest.
-----Output-----
If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests.
-----Examples-----
Input
3
-7 1
5 2
8 2
Output
1907
Input
2
57 1
22 2
Output
Impossible
Input
1
-5 1
Output
Infinity
Input
4
27 2
13 1
-50 1
8 2
Output
1897
-----Note-----
In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907.
In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
|
from sys import stdin
def main():
input()
mi, ma = -(10**9), 10**9
for s in stdin.read().splitlines():
c, d = map(int, s.split())
if d == 1:
if mi < 1900:
mi = 1900
elif ma > 1899:
ma = 1899
if mi > ma:
print("Impossible")
return
mi += c
ma += c
print(ma if ma < 10**8 else "Infinity")
main()
|
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP NUMBER NUMBER BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR IF VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR EXPR FUNC_CALL VAR STRING RETURN VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP NUMBER NUMBER VAR STRING EXPR FUNC_CALL VAR
|
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero.
Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating.
What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible".
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 200 000).
The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 β€ c_{i} β€ 100, 1 β€ d_{i} β€ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest.
-----Output-----
If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests.
-----Examples-----
Input
3
-7 1
5 2
8 2
Output
1907
Input
2
57 1
22 2
Output
Impossible
Input
1
-5 1
Output
Infinity
Input
4
27 2
13 1
-50 1
8 2
Output
1897
-----Note-----
In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907.
In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
|
n = int(input())
firstT, firstB = True, True
t = 1
b = 0
x = 0
for i in range(n):
c, d = map(int, input().split())
if d == 1:
if firstB:
b = 1900 - x
firstB = False
b = max(b, 1900 - x)
else:
if firstT:
t = 1900 - x
firstT = False
t = min(t, 1900 - x)
x += c
if firstT:
print("Infinity")
elif not firstB and b >= t:
print("Impossible")
else:
print(t - 1 + x)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR IF VAR ASSIGN VAR BIN_OP NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR VAR VAR IF VAR EXPR FUNC_CALL VAR STRING IF VAR VAR VAR EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR
|
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero.
Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating.
What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible".
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 200 000).
The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 β€ c_{i} β€ 100, 1 β€ d_{i} β€ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest.
-----Output-----
If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests.
-----Examples-----
Input
3
-7 1
5 2
8 2
Output
1907
Input
2
57 1
22 2
Output
Impossible
Input
1
-5 1
Output
Infinity
Input
4
27 2
13 1
-50 1
8 2
Output
1897
-----Note-----
In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907.
In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
|
n = int(input())
loi = []
infinity = False
impossible = False
for i in range(n):
loi.append(list(map(int, input().split(" "))))
if loi[0][1] == 1:
upper_bound = 99999999999999999
lower_bound = 1900
last_div = 1
if loi[0][1] == 2:
upper_bound = 1899
lower_bound = -99999999999999999
last_div = 2
for c, d in loi:
if d == 2 and lower_bound > 1899:
impossible = True
if d == 1 and upper_bound < 1900:
impossible = True
if d == 1:
lower_bound = max(lower_bound, 1900)
if d == 2:
upper_bound = min(upper_bound, 1899)
upper_bound += c
lower_bound += c
if lower_bound > upper_bound:
impossible = True
last_div = d
if impossible:
print("Impossible")
elif upper_bound > 10000000000000000:
print("Infinity")
else:
print(upper_bound)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING IF VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR IF VAR EXPR FUNC_CALL VAR STRING IF VAR NUMBER EXPR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR
|
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero.
Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating.
What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible".
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 200 000).
The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 β€ c_{i} β€ 100, 1 β€ d_{i} β€ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest.
-----Output-----
If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests.
-----Examples-----
Input
3
-7 1
5 2
8 2
Output
1907
Input
2
57 1
22 2
Output
Impossible
Input
1
-5 1
Output
Infinity
Input
4
27 2
13 1
-50 1
8 2
Output
1897
-----Note-----
In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907.
In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
|
MAX = 999999999
def do():
n = int(input())
mx = MAX
mn = -MAX
change, thisDiv = list(map(int, input().split()))
ratingChange = [0, change]
divChange = [0, thisDiv]
for i in range(n - 1):
change, thisDiv = list(map(int, input().split()))
ratingChange.append(ratingChange[-1] + change)
divChange.append(thisDiv)
for i in range(n):
if divChange[i + 1] == 1:
mn = max(1900 - ratingChange[i], mn)
else:
mx = min(1899 - ratingChange[i], mx)
if mn > mx:
return "Impossible"
elif mx == MAX:
return "Infinity"
else:
return str(mx + ratingChange[-1])
print(do())
|
ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST NUMBER VAR ASSIGN VAR LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER VAR VAR VAR IF VAR VAR RETURN STRING IF VAR VAR RETURN STRING RETURN FUNC_CALL VAR BIN_OP VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR
|
Every Codeforces user has rating, described with one integer, possibly negative or zero. Users are divided into two divisions. The first division is for users with rating 1900 or higher. Those with rating 1899 or lower belong to the second division. In every contest, according to one's performance, his or her rating changes by some value, possibly negative or zero.
Limak competed in n contests in the year 2016. He remembers that in the i-th contest he competed in the division d_{i} (i.e. he belonged to this division just before the start of this contest) and his rating changed by c_{i} just after the contest. Note that negative c_{i} denotes the loss of rating.
What is the maximum possible rating Limak can have right now, after all n contests? If his rating may be arbitrarily big, print "Infinity". If there is no scenario matching the given information, print "Impossible".
-----Input-----
The first line of the input contains a single integer n (1 β€ n β€ 200 000).
The i-th of next n lines contains two integers c_{i} and d_{i} ( - 100 β€ c_{i} β€ 100, 1 β€ d_{i} β€ 2), describing Limak's rating change after the i-th contest and his division during the i-th contest contest.
-----Output-----
If Limak's current rating can be arbitrarily big, print "Infinity" (without quotes). If the situation is impossible, print "Impossible" (without quotes). Otherwise print one integer, denoting the maximum possible value of Limak's current rating, i.e. rating after the n contests.
-----Examples-----
Input
3
-7 1
5 2
8 2
Output
1907
Input
2
57 1
22 2
Output
Impossible
Input
1
-5 1
Output
Infinity
Input
4
27 2
13 1
-50 1
8 2
Output
1897
-----Note-----
In the first sample, the following scenario matches all information Limak remembers and has maximum possible final rating: Limak has rating 1901 and belongs to the division 1 in the first contest. His rating decreases by 7. With rating 1894 Limak is in the division 2. His rating increases by 5. Limak has rating 1899 and is still in the division 2. In the last contest of the year he gets + 8 and ends the year with rating 1907.
In the second sample, it's impossible that Limak is in the division 1, his rating increases by 57 and after that Limak is in the division 2 in the second contest.
|
FIRST_DIV_START = 1900
def solve():
n = int(input())
min_rating = None
max_rating = None
for _ in range(n):
c, d = list(map(int, input().split()))
if d == 2:
if max_rating is None:
max_rating = FIRST_DIV_START - 1
else:
max_rating = min(FIRST_DIV_START - 1, max_rating)
if min_rating is not None and min_rating > max_rating:
return "Impossible"
max_rating += c
if min_rating is not None:
min_rating += c
else:
if min_rating is None:
min_rating = FIRST_DIV_START
else:
min_rating = max(min_rating, FIRST_DIV_START)
if max_rating is not None and min_rating > max_rating:
return "Impossible"
min_rating += c
if max_rating is not None:
max_rating += c
if max_rating is None:
return "Infinity"
return max_rating
def __starting_point():
print(solve())
__starting_point()
|
ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NONE ASSIGN VAR NONE FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF VAR NUMBER IF VAR NONE ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR NONE VAR VAR RETURN STRING VAR VAR IF VAR NONE VAR VAR IF VAR NONE ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR NONE VAR VAR RETURN STRING VAR VAR IF VAR NONE VAR VAR IF VAR NONE RETURN STRING RETURN VAR FUNC_DEF EXPR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.