description stringlengths 171 4k | code stringlengths 94 3.98k | normalized_code stringlengths 57 4.99k |
|---|---|---|
There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $x$.
Each programmer should belong to at most one team. Some programmers may be left without a team.
Calculate the maximum number of teams that you can assemble.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 1000$)Β β the number of test cases.
The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5; 1 \le x \le 10^9$)Β β the number of programmers and the restriction of team skill respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the skill of the $i$-th programmer.
The sum of $n$ over all inputs does not exceed $10^5$.
-----Output-----
For each test case print one integer β the maximum number of teams that you can assemble.
-----Example-----
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0 | def main():
for _ in range(int(input())):
n, x = list(map(int, input().split()))
arr = list(map(int, input().split()))
arr = sorted(arr, reverse=True)
k = 1
i = 0
count = 0
while i + k - 1 < n:
if arr[i + k - 1] >= x / k:
i += k
count += 1
else:
k += 1
print(count)
main() | FUNC_DEF FOR VAR FUNC_CALL 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 ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP BIN_OP VAR VAR NUMBER VAR IF VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $x$.
Each programmer should belong to at most one team. Some programmers may be left without a team.
Calculate the maximum number of teams that you can assemble.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 1000$)Β β the number of test cases.
The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5; 1 \le x \le 10^9$)Β β the number of programmers and the restriction of team skill respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the skill of the $i$-th programmer.
The sum of $n$ over all inputs does not exceed $10^5$.
-----Output-----
For each test case print one integer β the maximum number of teams that you can assemble.
-----Example-----
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0 | def mergeSort(nlist):
if len(nlist) > 1:
mid = len(nlist) // 2
lefthalf = nlist[:mid]
righthalf = nlist[mid:]
mergeSort(lefthalf)
mergeSort(righthalf)
i = j = k = 0
while i < len(lefthalf) and j < len(righthalf):
if lefthalf[i] < righthalf[j]:
nlist[k] = lefthalf[i]
i = i + 1
else:
nlist[k] = righthalf[j]
j = j + 1
k = k + 1
while i < len(lefthalf):
nlist[k] = lefthalf[i]
i = i + 1
k = k + 1
while j < len(righthalf):
nlist[k] = righthalf[j]
j = j + 1
k = k + 1
return nlist
t = int(input())
for i in range(t):
n, x = input().split()
teams = 0
l = [int(i) for i in input().split()]
a = []
l = mergeSort(l)
for i in range(len(l) - 1, -1, -1):
a.append(l[i])
mini = a[-1]
if mini * len(a) >= int(x):
teams += 1
a = []
print(teams) | FUNC_DEF IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER IF BIN_OP VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR |
There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $x$.
Each programmer should belong to at most one team. Some programmers may be left without a team.
Calculate the maximum number of teams that you can assemble.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 1000$)Β β the number of test cases.
The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5; 1 \le x \le 10^9$)Β β the number of programmers and the restriction of team skill respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the skill of the $i$-th programmer.
The sum of $n$ over all inputs does not exceed $10^5$.
-----Output-----
For each test case print one integer β the maximum number of teams that you can assemble.
-----Example-----
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0 | for _ in range(int(input())):
a = input().split(" ")
n, x = int(a[0]), int(a[1])
a = input().split(" ")
for i in range(n):
a[i] = int(a[i])
a.sort(reverse=True)
ans = 0
i = 0
while a != [] and i < len(a):
if a[i] >= x:
ans += 1
i += 1
else:
j = i
while j < len(a):
if a[j] * (j - i + 1) >= x:
ans += 1
break
j += 1
i = j + 1
if i >= len(a):
break
print(ans) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR FUNC_CALL VAR VAR NUMBER FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR LIST VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR WHILE VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $x$.
Each programmer should belong to at most one team. Some programmers may be left without a team.
Calculate the maximum number of teams that you can assemble.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 1000$)Β β the number of test cases.
The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5; 1 \le x \le 10^9$)Β β the number of programmers and the restriction of team skill respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the skill of the $i$-th programmer.
The sum of $n$ over all inputs does not exceed $10^5$.
-----Output-----
For each test case print one integer β the maximum number of teams that you can assemble.
-----Example-----
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0 | n = int(input())
for i in range(n):
cnt, cur = 0, 1
a, b = map(int, input().split())
l = list(map(int, input().split()))[:a]
l.sort(reverse=True)
k = 0
for x in l:
if x * cur >= b:
cnt = cnt + 1
cur = 0
cur += 1
print(cnt) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER 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 VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $x$.
Each programmer should belong to at most one team. Some programmers may be left without a team.
Calculate the maximum number of teams that you can assemble.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 1000$)Β β the number of test cases.
The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5; 1 \le x \le 10^9$)Β β the number of programmers and the restriction of team skill respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the skill of the $i$-th programmer.
The sum of $n$ over all inputs does not exceed $10^5$.
-----Output-----
For each test case print one integer β the maximum number of teams that you can assemble.
-----Example-----
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0 | for _ in range(int(input())):
n, t = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
F = [0] * (n + 3)
ans = 0
for x in range(0, n):
x = int(x)
m = int((t - 1) / a[x]) + 1
if m <= x + 1:
F[x + 1] = max(F[x + 1], F[x + 1 - m] + 1)
ans = max(ans, F[x + 1])
print(ans) | FOR VAR FUNC_CALL 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 EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $x$.
Each programmer should belong to at most one team. Some programmers may be left without a team.
Calculate the maximum number of teams that you can assemble.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 1000$)Β β the number of test cases.
The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5; 1 \le x \le 10^9$)Β β the number of programmers and the restriction of team skill respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the skill of the $i$-th programmer.
The sum of $n$ over all inputs does not exceed $10^5$.
-----Output-----
For each test case print one integer β the maximum number of teams that you can assemble.
-----Example-----
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0 | __MULTITEST = True
def solve():
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
group = 0
ptr = n - 1
members = 0
currentMin = int(10000000000.0)
while ptr > -1:
currentMin = min(currentMin, a[ptr])
members += 1
if currentMin * members >= x:
group += 1
members = 0
currentMin = int(10000000000.0)
ptr -= 1
print(group)
t = int(input()) if __MULTITEST else 1
for tt in range(t):
solve() | ASSIGN VAR NUMBER FUNC_DEF 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 EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $x$.
Each programmer should belong to at most one team. Some programmers may be left without a team.
Calculate the maximum number of teams that you can assemble.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 1000$)Β β the number of test cases.
The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5; 1 \le x \le 10^9$)Β β the number of programmers and the restriction of team skill respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the skill of the $i$-th programmer.
The sum of $n$ over all inputs does not exceed $10^5$.
-----Output-----
For each test case print one integer β the maximum number of teams that you can assemble.
-----Example-----
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0 | for _ in range(int(input())):
nx = list(map(int, input().strip().split()))
n, x = nx[0], nx[1]
li = list(map(int, input().strip().split()))
li.sort()
p = list(reversed(li))
temp, maxi = 1, 0
for i in range(n):
if p[i] * temp >= x:
maxi += 1
temp = 1
else:
temp += 1
print(maxi) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $x$.
Each programmer should belong to at most one team. Some programmers may be left without a team.
Calculate the maximum number of teams that you can assemble.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 1000$)Β β the number of test cases.
The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5; 1 \le x \le 10^9$)Β β the number of programmers and the restriction of team skill respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the skill of the $i$-th programmer.
The sum of $n$ over all inputs does not exceed $10^5$.
-----Output-----
For each test case print one integer β the maximum number of teams that you can assemble.
-----Example-----
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0 | for test_i in range(int(input())):
n, x = map(int, input().split())
skills = list(map(int, input().split()))
if x == 1:
print(n)
else:
skills.sort()
i0 = 0
while skills[i0] == 1:
i0 += 1
if i0 == n:
break
ans = 0
di = 0
for i in range(1, n - i0 + 1):
if (x - 1) // skills[-i] + 1 - (i - di) <= 0:
ans += 1
di = i
ans += (n - di) // x
print(ans) | FOR VAR FUNC_CALL 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 NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR NUMBER IF BIN_OP BIN_OP BIN_OP BIN_OP VAR NUMBER VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR |
There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $x$.
Each programmer should belong to at most one team. Some programmers may be left without a team.
Calculate the maximum number of teams that you can assemble.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 1000$)Β β the number of test cases.
The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5; 1 \le x \le 10^9$)Β β the number of programmers and the restriction of team skill respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the skill of the $i$-th programmer.
The sum of $n$ over all inputs does not exceed $10^5$.
-----Output-----
For each test case print one integer β the maximum number of teams that you can assemble.
-----Example-----
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0 | t = int(input())
for i in range(t):
n, x = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
temp = []
minimum = 10000000000
total = 0
for j in range(n - 1, -1, -1):
temp.append(l[j])
if l[j] < minimum:
minimum = l[j]
if len(temp) * minimum >= x:
temp = []
total += 1
minimum = 10000000000
print(total) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR 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 EXPR FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER EXPR FUNC_CALL VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP FUNC_CALL VAR VAR VAR VAR ASSIGN VAR LIST VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $x$.
Each programmer should belong to at most one team. Some programmers may be left without a team.
Calculate the maximum number of teams that you can assemble.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 1000$)Β β the number of test cases.
The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5; 1 \le x \le 10^9$)Β β the number of programmers and the restriction of team skill respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the skill of the $i$-th programmer.
The sum of $n$ over all inputs does not exceed $10^5$.
-----Output-----
For each test case print one integer β the maximum number of teams that you can assemble.
-----Example-----
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0 | t = int(input())
for _ in range(t):
n, x = map(int, input().split())
a = [int(i) for i in input().split()]
a.sort()
res = 0
acc = 0
min_el = float("inf")
for i in range(n - 1, -1, -1):
if a[i] >= x:
res += 1
min_el = float("inf")
acc = 0
else:
acc += 1
if min_el > a[i]:
min_el = a[i]
if acc * min_el >= x:
res += 1
min_el = float("inf")
acc = 0
print(res) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR 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 EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $x$.
Each programmer should belong to at most one team. Some programmers may be left without a team.
Calculate the maximum number of teams that you can assemble.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 1000$)Β β the number of test cases.
The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5; 1 \le x \le 10^9$)Β β the number of programmers and the restriction of team skill respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the skill of the $i$-th programmer.
The sum of $n$ over all inputs does not exceed $10^5$.
-----Output-----
For each test case print one integer β the maximum number of teams that you can assemble.
-----Example-----
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0 | def fast(arr, x):
result = 0
arr.sort(reverse=True)
minNum = float("inf")
currLen = 0
rollingVal = 0
for num in arr:
minNum = min(minNum, num)
currLen += 1
rollingVal = currLen * minNum
if rollingVal >= x:
result += 1
minNum = float("inf")
currLen = 0
rollingVal = 0
return result
def main():
t = int(input())
for _ in range(t):
n, x = [int(x) for x in input().split()]
arr = [int(x) for x in input().split()]
result = fast(arr, x)
print(result)
main() | FUNC_DEF ASSIGN VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR NUMBER ASSIGN VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR 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 FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $x$.
Each programmer should belong to at most one team. Some programmers may be left without a team.
Calculate the maximum number of teams that you can assemble.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 1000$)Β β the number of test cases.
The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5; 1 \le x \le 10^9$)Β β the number of programmers and the restriction of team skill respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the skill of the $i$-th programmer.
The sum of $n$ over all inputs does not exceed $10^5$.
-----Output-----
For each test case print one integer β the maximum number of teams that you can assemble.
-----Example-----
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0 | def solve():
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
j = 0
ans = 0
for i in range(n):
if (i - j + 1) * a[i] >= x:
j = i + 1
ans += 1
print(ans)
t = int(input())
for test in range(t):
solve() | FUNC_DEF 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 EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER 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$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $x$.
Each programmer should belong to at most one team. Some programmers may be left without a team.
Calculate the maximum number of teams that you can assemble.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 1000$)Β β the number of test cases.
The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5; 1 \le x \le 10^9$)Β β the number of programmers and the restriction of team skill respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the skill of the $i$-th programmer.
The sum of $n$ over all inputs does not exceed $10^5$.
-----Output-----
For each test case print one integer β the maximum number of teams that you can assemble.
-----Example-----
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0 | def solve():
global N, X, A
A.sort(reverse=True)
i = 0
sol = 0
skill = None
membs = 0
while i < len(A):
if skill is not None and skill * membs >= X:
sol += 1
membs = 0
skill = None
skill = A[i] if skill is None else min(skill, A[i])
membs += 1
i += 1
return sol + int(skill is not None and skill * membs >= X)
for _ in range(int(input())):
N, X = map(int, input().split())
A = list(map(int, input().split()))
sol = solve()
print(sol) | FUNC_DEF EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NONE ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR NONE BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NONE ASSIGN VAR VAR NONE VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER VAR NUMBER RETURN BIN_OP VAR FUNC_CALL VAR VAR NONE BIN_OP VAR VAR VAR FOR VAR FUNC_CALL 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 FUNC_CALL VAR EXPR FUNC_CALL VAR VAR |
There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $x$.
Each programmer should belong to at most one team. Some programmers may be left without a team.
Calculate the maximum number of teams that you can assemble.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 1000$)Β β the number of test cases.
The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5; 1 \le x \le 10^9$)Β β the number of programmers and the restriction of team skill respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the skill of the $i$-th programmer.
The sum of $n$ over all inputs does not exceed $10^5$.
-----Output-----
For each test case print one integer β the maximum number of teams that you can assemble.
-----Example-----
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0 | for _ in range(int(input())):
n, x = [*map(int, input().split())]
a = [*map(int, input().split())]
a.sort()
count = 0
se = 0
a = a[::-1]
b = []
for i in a:
if i >= x:
count += 1
else:
b.append(i)
while len(b) != 0:
if len(b) == 0:
print(count)
break
else:
pointer1 = 0
for i in range(pointer1, len(b)):
ans = b[i]
se += 1
if ans * se >= x:
se = 0
pointer1 = i + 1
count += 1
print(count)
break
if len(b) == 0:
print(count) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $x$.
Each programmer should belong to at most one team. Some programmers may be left without a team.
Calculate the maximum number of teams that you can assemble.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 1000$)Β β the number of test cases.
The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5; 1 \le x \le 10^9$)Β β the number of programmers and the restriction of team skill respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the skill of the $i$-th programmer.
The sum of $n$ over all inputs does not exceed $10^5$.
-----Output-----
For each test case print one integer β the maximum number of teams that you can assemble.
-----Example-----
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0 | for _ in range(int(input())):
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
i = n - 1
count = 0
while i >= 0 and a[i] >= x:
count += 1
i -= 1
if i >= 0:
j = i - 1
while j >= 0:
if a[j] * (i - j + 1) >= x:
count += 1
i = j - 1
j -= 1
print(count) | FOR VAR FUNC_CALL 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 EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $x$.
Each programmer should belong to at most one team. Some programmers may be left without a team.
Calculate the maximum number of teams that you can assemble.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 1000$)Β β the number of test cases.
The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5; 1 \le x \le 10^9$)Β β the number of programmers and the restriction of team skill respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the skill of the $i$-th programmer.
The sum of $n$ over all inputs does not exceed $10^5$.
-----Output-----
For each test case print one integer β the maximum number of teams that you can assemble.
-----Example-----
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0 | def main():
n, x = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
a.sort(reverse=True)
z = 0
beg = 0
end = 0
while end < n:
if a[end] * (end - beg + 1) >= x:
z += 1
beg = end + 1
end = beg + 0
else:
end += 1
print(z)
for _ in range(int(input())):
main() | FUNC_DEF ASSIGN 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 EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER 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$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $x$.
Each programmer should belong to at most one team. Some programmers may be left without a team.
Calculate the maximum number of teams that you can assemble.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 1000$)Β β the number of test cases.
The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5; 1 \le x \le 10^9$)Β β the number of programmers and the restriction of team skill respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the skill of the $i$-th programmer.
The sum of $n$ over all inputs does not exceed $10^5$.
-----Output-----
For each test case print one integer β the maximum number of teams that you can assemble.
-----Example-----
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0 | testCases = int(input())
while testCases:
testCases -= 1
x = input()
y = input()
x = list(map(int, x.split()))
y = list(map(int, y.split()))
y.sort()
y = y[::-1]
i = 0
step = 1
teams = 0
while i < len(y):
if y[i] * step >= x[1]:
teams += 1
step = 1
else:
step += 1
i += 1
print(teams) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $x$.
Each programmer should belong to at most one team. Some programmers may be left without a team.
Calculate the maximum number of teams that you can assemble.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 1000$)Β β the number of test cases.
The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5; 1 \le x \le 10^9$)Β β the number of programmers and the restriction of team skill respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the skill of the $i$-th programmer.
The sum of $n$ over all inputs does not exceed $10^5$.
-----Output-----
For each test case print one integer β the maximum number of teams that you can assemble.
-----Example-----
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0 | import sys
input = sys.stdin.readline
def ceil(x):
if x != int(x):
x = int(x) + 1
return x
def swaparr(arr, a, b):
temp = arr[a]
arr[a] = arr[b]
arr[b] = temp
def gcd(a, b):
if b == 0:
return a
return gcd(b, a % b)
def nCr(n, k):
if k > n - k:
k = n - k
res = 1
for i in range(k):
res = res * (n - i)
res = res / (i + 1)
return int(res)
def upper_bound(a, x, lo=0, hi=None):
if hi == None:
hi = len(a)
while lo < hi:
mid = (lo + hi) // 2
if a[mid] < x:
lo = mid + 1
else:
hi = mid
return lo
def primefs(n):
primes = {}
while n % 2 == 0 and n > 0:
primes[2] = primes.get(2, 0) + 1
n = n // 2
for i in range(3, int(n**0.5) + 2, 2):
while n % i == 0 and n > 0:
primes[i] = primes.get(i, 0) + 1
n = n // i
if n > 2:
primes[n] = primes.get(n, 0) + 1
return primes
def power(x, y, p):
res = 1
x = x % p
if x == 0:
return 0
while y > 0:
if y & 1 == 1:
res = res * x % p
y = y >> 1
x = x * x % p
return res
def swap(a, b):
temp = a
a = b
b = temp
return a, b
def find(x, link):
p = x
while p != link[p]:
p = link[p]
while x != p:
nex = link[x]
link[x] = p
x = nex
return p
def union(x, y, link, size):
x = find(x, link)
y = find(y, link)
if size[x] < size[y]:
x, y = swap(x, y)
if x != y:
size[x] += size[y]
link[y] = x
def sieve(n):
prime = [(True) for i in range(n + 1)]
p = 2
while p * p <= n:
if prime[p] == True:
for i in range(p * p, n + 1, p):
prime[i] = False
p += 1
return prime
MAXN = int(100000.0 + 5)
def spf_sieve():
spf[1] = 1
for i in range(2, MAXN):
spf[i] = i
for i in range(4, MAXN, 2):
spf[i] = 2
for i in range(3, ceil(MAXN**0.5), 2):
if spf[i] == i:
for j in range(i * i, MAXN, i):
if spf[j] == j:
spf[j] = i
def factoriazation(x):
ret = {}
while x != 1:
ret[spf[x]] = ret.get(spf[x], 0) + 1
x = x // spf[x]
return ret
def int_array():
return list(map(int, input().strip().split()))
def str_array():
return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float("inf")
NINF = -float("inf")
for _ in range(int(input())):
n, x = int_array()
a = sorted(int_array())
ans = 0
while a and a[-1] >= x:
ans += 1
a.pop()
num = 0
t = INF
while a:
num += 1
t = min(a.pop(), t)
if num * t >= x:
ans += 1
num = 0
t = INF
print(ans) | IMPORT ASSIGN VAR VAR FUNC_DEF IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_DEF IF VAR NUMBER RETURN VAR RETURN FUNC_CALL VAR VAR BIN_OP VAR VAR FUNC_DEF IF VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR FUNC_DEF NUMBER NONE IF VAR NONE ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR DICT WHILE BIN_OP VAR NUMBER NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP FUNC_CALL VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR VAR IF VAR NUMBER RETURN NUMBER WHILE VAR NUMBER IF BIN_OP VAR NUMBER NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR VAR FUNC_DEF ASSIGN VAR VAR WHILE VAR VAR VAR ASSIGN VAR VAR VAR WHILE VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR VAR VAR IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR NUMBER VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FUNC_DEF ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR IF VAR VAR VAR ASSIGN VAR VAR VAR FUNC_DEF ASSIGN VAR DICT WHILE VAR NUMBER ASSIGN VAR VAR VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR RETURN VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $x$.
Each programmer should belong to at most one team. Some programmers may be left without a team.
Calculate the maximum number of teams that you can assemble.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 1000$)Β β the number of test cases.
The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5; 1 \le x \le 10^9$)Β β the number of programmers and the restriction of team skill respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the skill of the $i$-th programmer.
The sum of $n$ over all inputs does not exceed $10^5$.
-----Output-----
For each test case print one integer β the maximum number of teams that you can assemble.
-----Example-----
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0 | t = int(input())
for i in range(t):
n, x = list(map(int, input().split()))
nums = list(map(int, input().split()))
nums.sort(reverse=True)
teams = 0
team_members = 0
team_min = float("inf")
for num in nums:
team_members += 1
team_min = min(team_min, num)
value = team_members * team_min
if value >= x:
teams += 1
team_members = 0
team_min = float("inf")
print(teams) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR 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 EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR VAR |
There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $x$.
Each programmer should belong to at most one team. Some programmers may be left without a team.
Calculate the maximum number of teams that you can assemble.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 1000$)Β β the number of test cases.
The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5; 1 \le x \le 10^9$)Β β the number of programmers and the restriction of team skill respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the skill of the $i$-th programmer.
The sum of $n$ over all inputs does not exceed $10^5$.
-----Output-----
For each test case print one integer β the maximum number of teams that you can assemble.
-----Example-----
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0 | def pro(arr, x):
arr.sort(reverse=True)
n = len(arr)
c = 1
ans = 0
mini = arr[0]
for i in range(n):
if c * arr[i] >= x:
ans += 1
c = 1
else:
c += 1
print(ans)
t = int(input())
for i in range(t):
n, k = list(map(int, input().split()))
arr = list(map(int, input().split()))
pro(arr, k) | FUNC_DEF EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR 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 EXPR FUNC_CALL VAR VAR VAR |
There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $x$.
Each programmer should belong to at most one team. Some programmers may be left without a team.
Calculate the maximum number of teams that you can assemble.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 1000$)Β β the number of test cases.
The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5; 1 \le x \le 10^9$)Β β the number of programmers and the restriction of team skill respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the skill of the $i$-th programmer.
The sum of $n$ over all inputs does not exceed $10^5$.
-----Output-----
For each test case print one integer β the maximum number of teams that you can assemble.
-----Example-----
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0 | def solve():
n, x = map(int, input().split(" "))
a = list(map(int, input().split(" ")))
a = sorted(a)
a = a[::-1]
i = 0
t = 1
num = 0
while i < n:
while t * a[i] < x:
i += 1
t += 1
if i == n:
break
if i == n:
break
if a[i] * t >= x:
num += 1
t = 1
i += 1
print(num)
t = int(input())
while t:
t -= 1
solve() | FUNC_DEF ASSIGN 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 FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR WHILE BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR IF VAR VAR IF BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER EXPR FUNC_CALL VAR |
There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $x$.
Each programmer should belong to at most one team. Some programmers may be left without a team.
Calculate the maximum number of teams that you can assemble.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 1000$)Β β the number of test cases.
The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5; 1 \le x \le 10^9$)Β β the number of programmers and the restriction of team skill respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the skill of the $i$-th programmer.
The sum of $n$ over all inputs does not exceed $10^5$.
-----Output-----
For each test case print one integer β the maximum number of teams that you can assemble.
-----Example-----
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0 | t = int(input())
for test_case in range(t):
n, x = [int(x) for x in input().split()]
res = 0
a = []
a = [int(y) for y in input().split()]
a.sort()
ind = 0
for i in range(n - 1, -1, -1):
if a[i] >= x:
res += 1
ind += 1
m = len(a) - 1 - ind
sum = 1
while m > 0:
sum = 1
for i in range(m, -1, -1):
if sum * a[i] >= x:
res += 1
m -= 1
break
else:
sum += 1
m -= 1
print()
print(res)
print() | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR LIST ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR NUMBER VAR ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $x$.
Each programmer should belong to at most one team. Some programmers may be left without a team.
Calculate the maximum number of teams that you can assemble.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 1000$)Β β the number of test cases.
The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5; 1 \le x \le 10^9$)Β β the number of programmers and the restriction of team skill respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the skill of the $i$-th programmer.
The sum of $n$ over all inputs does not exceed $10^5$.
-----Output-----
For each test case print one integer β the maximum number of teams that you can assemble.
-----Example-----
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0 | T = int(input())
while T > 0:
n, x = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
need = [0] * n
for i in range(n):
temp = x // arr[i]
if x % arr[i] != 0:
temp += 1
need[i] = temp
dp = [0] * n
res = 0
for i in range(n - 1, -1, -1):
index = i + need[i]
if index == n:
dp[i] = 1
elif index < n:
dp[i] = 1 + dp[index]
res = max(res, dp[i])
print(res)
T -= 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER 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 EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR ASSIGN VAR VAR BIN_OP NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER |
There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $x$.
Each programmer should belong to at most one team. Some programmers may be left without a team.
Calculate the maximum number of teams that you can assemble.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 1000$)Β β the number of test cases.
The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5; 1 \le x \le 10^9$)Β β the number of programmers and the restriction of team skill respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the skill of the $i$-th programmer.
The sum of $n$ over all inputs does not exceed $10^5$.
-----Output-----
For each test case print one integer β the maximum number of teams that you can assemble.
-----Example-----
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0 | cases = int(input())
for i in range(cases):
l1 = input().split(" ")
l2 = input().split(" ")
n = int(l1[0])
x = int(l1[1])
arr = []
for a in l2:
arr.append(int(a))
arr.sort(reverse=True)
g = 0
current = 0
ini = 0
endpoint = 0
while ini < len(arr):
current = arr[ini]
if current >= x:
g += 1
endpoint = ini + 1
elif current < x:
check = current * (ini - endpoint + 1)
if check >= x:
g += 1
endpoint = ini + 1
ini += 1
print(g) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $x$.
Each programmer should belong to at most one team. Some programmers may be left without a team.
Calculate the maximum number of teams that you can assemble.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 1000$)Β β the number of test cases.
The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5; 1 \le x \le 10^9$)Β β the number of programmers and the restriction of team skill respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the skill of the $i$-th programmer.
The sum of $n$ over all inputs does not exceed $10^5$.
-----Output-----
For each test case print one integer β the maximum number of teams that you can assemble.
-----Example-----
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0 | for _ in range(int(input())):
n, m = map(int, input().split())
a = sorted(map(int, input().split()))
b = [0] * (n + 1)
for i in range(n - 1, -1, -1):
b[i] = b[i + 1]
x = (m + a[i] - 1) // a[i]
if i + x <= n:
b[i] = max(b[i], 1 + b[i + x])
print(b[0]) | FOR VAR FUNC_CALL 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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP NUMBER VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR NUMBER |
There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $x$.
Each programmer should belong to at most one team. Some programmers may be left without a team.
Calculate the maximum number of teams that you can assemble.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 1000$)Β β the number of test cases.
The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5; 1 \le x \le 10^9$)Β β the number of programmers and the restriction of team skill respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the skill of the $i$-th programmer.
The sum of $n$ over all inputs does not exceed $10^5$.
-----Output-----
For each test case print one integer β the maximum number of teams that you can assemble.
-----Example-----
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0 | import sys
inputlist = sys.stdin.readlines()
number_of_testcases = int(inputlist[0].strip())
i = 0
while i < 2 * number_of_testcases:
i += 1
n, x = list(map(int, inputlist[i].strip().split(" ")))
i += 1
numbers_list = list(map(int, inputlist[i].strip().split(" ")))
numbers_list.sort(reverse=True)
total_teams = 0
players_till_now = 0
for j in numbers_list:
players_till_now += 1
if players_till_now * j >= x:
total_teams += 1
players_till_now = 0
print(total_teams) | IMPORT ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR STRING VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR VAR STRING EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $x$.
Each programmer should belong to at most one team. Some programmers may be left without a team.
Calculate the maximum number of teams that you can assemble.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 1000$)Β β the number of test cases.
The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5; 1 \le x \le 10^9$)Β β the number of programmers and the restriction of team skill respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the skill of the $i$-th programmer.
The sum of $n$ over all inputs does not exceed $10^5$.
-----Output-----
For each test case print one integer β the maximum number of teams that you can assemble.
-----Example-----
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0 | t = int(input())
while t:
t = t - 1
n, x = map(int, input().split())
a = list(map(int, input().split()))
cnt = 0
a.sort(reverse=True)
i = 0
while 1:
if i == n:
break
if a[i] >= x:
cnt += 1
i += 1
continue
pro = a[i]
j = 1
i += 1
while pro < x and i < n:
j += 1
pro = a[i] * j
i += 1
if pro >= x:
cnt += 1
print(cnt) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR ASSIGN VAR BIN_OP VAR NUMBER 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 NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER IF VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER WHILE VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $x$.
Each programmer should belong to at most one team. Some programmers may be left without a team.
Calculate the maximum number of teams that you can assemble.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 1000$)Β β the number of test cases.
The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5; 1 \le x \le 10^9$)Β β the number of programmers and the restriction of team skill respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the skill of the $i$-th programmer.
The sum of $n$ over all inputs does not exceed $10^5$.
-----Output-----
For each test case print one integer β the maximum number of teams that you can assemble.
-----Example-----
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0 | t = int(input())
for i in range(t):
n, x = map(int, input().split())
l = list(map(int, input().split()))
l.sort()
j = n - 1
pointer = n
pointer2 = n - 1
count = 0
while j >= 0:
if l[j] * (pointer - j) >= x:
pointer = j
count = count + 1
j = j - 1
print(count) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR 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 EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $x$.
Each programmer should belong to at most one team. Some programmers may be left without a team.
Calculate the maximum number of teams that you can assemble.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 1000$)Β β the number of test cases.
The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5; 1 \le x \le 10^9$)Β β the number of programmers and the restriction of team skill respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the skill of the $i$-th programmer.
The sum of $n$ over all inputs does not exceed $10^5$.
-----Output-----
For each test case print one integer β the maximum number of teams that you can assemble.
-----Example-----
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0 | t = int(input())
while t:
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
cur = 0
ind = 1
for i in a:
if i * ind >= k:
ind = 0
cur += 1
ind += 1
print(cur)
t = t - 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE 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 EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER |
There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $x$.
Each programmer should belong to at most one team. Some programmers may be left without a team.
Calculate the maximum number of teams that you can assemble.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 1000$)Β β the number of test cases.
The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5; 1 \le x \le 10^9$)Β β the number of programmers and the restriction of team skill respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the skill of the $i$-th programmer.
The sum of $n$ over all inputs does not exceed $10^5$.
-----Output-----
For each test case print one integer β the maximum number of teams that you can assemble.
-----Example-----
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0 | import sys
input = sys.stdin.readline
output = lambda x: sys.stdout.write(x + "\n")
for _ in range(int(input())):
n, x = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
res = 0
cur = 0
for val in a:
if val * (cur + 1) >= x:
cur = 0
res += 1
else:
cur += 1
output(str(res)) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP 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 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 FOR VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $x$.
Each programmer should belong to at most one team. Some programmers may be left without a team.
Calculate the maximum number of teams that you can assemble.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 1000$)Β β the number of test cases.
The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5; 1 \le x \le 10^9$)Β β the number of programmers and the restriction of team skill respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the skill of the $i$-th programmer.
The sum of $n$ over all inputs does not exceed $10^5$.
-----Output-----
For each test case print one integer β the maximum number of teams that you can assemble.
-----Example-----
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0 | def cin():
return map(int, input().split())
for t in range(int(input())):
n, x = cin()
a = list(cin())
b = sorted(a, reverse=True)
ans = 0
j = 0
for i in range(n):
if b[i] * (i - j + 1) >= x:
ans += 1
j = i + 1
print(ans) | FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $x$.
Each programmer should belong to at most one team. Some programmers may be left without a team.
Calculate the maximum number of teams that you can assemble.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 1000$)Β β the number of test cases.
The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5; 1 \le x \le 10^9$)Β β the number of programmers and the restriction of team skill respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the skill of the $i$-th programmer.
The sum of $n$ over all inputs does not exceed $10^5$.
-----Output-----
For each test case print one integer β the maximum number of teams that you can assemble.
-----Example-----
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0 | for _ in range(int(input())):
n, x = map(int, input().split())
lis = sorted(map(int, input().split()), reverse=True)
ans = cur = mi = no = 0
for i in range(n):
if cur == 0:
no = 1
cur = 1
else:
no += 1
mi = lis[i]
if mi * no >= x:
ans += 1
no = 0
cur = 0
print(ans) | FOR VAR FUNC_CALL 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 NUMBER ASSIGN VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $x$.
Each programmer should belong to at most one team. Some programmers may be left without a team.
Calculate the maximum number of teams that you can assemble.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 1000$)Β β the number of test cases.
The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5; 1 \le x \le 10^9$)Β β the number of programmers and the restriction of team skill respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the skill of the $i$-th programmer.
The sum of $n$ over all inputs does not exceed $10^5$.
-----Output-----
For each test case print one integer β the maximum number of teams that you can assemble.
-----Example-----
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0 | class Main:
def main(self):
t = int(input())
for t1 in range(0, t):
n1 = list(map(int, input().split()))
x = n1[1]
a = reversed(sorted(list(map(int, input().split()))))
result = 0
count = 0
for a1 in a:
count += 1
if a1 * count >= x:
result += 1
count = 0
print(result)
Main().main() | CLASS_DEF FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL FUNC_CALL VAR |
There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $x$.
Each programmer should belong to at most one team. Some programmers may be left without a team.
Calculate the maximum number of teams that you can assemble.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 1000$)Β β the number of test cases.
The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5; 1 \le x \le 10^9$)Β β the number of programmers and the restriction of team skill respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the skill of the $i$-th programmer.
The sum of $n$ over all inputs does not exceed $10^5$.
-----Output-----
For each test case print one integer β the maximum number of teams that you can assemble.
-----Example-----
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0 | t = int(input())
for i in range(t):
put = input()
n = int(put.split()[0])
x = int(put.split()[1])
num = 0
items = 1
a = list(map(int, input().split()))
a.sort(reverse=True)
for z in a:
if z * items >= x:
num = num + 1
items = 0
items += 1
print(num) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER FOR VAR VAR IF BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $x$.
Each programmer should belong to at most one team. Some programmers may be left without a team.
Calculate the maximum number of teams that you can assemble.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 1000$)Β β the number of test cases.
The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5; 1 \le x \le 10^9$)Β β the number of programmers and the restriction of team skill respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the skill of the $i$-th programmer.
The sum of $n$ over all inputs does not exceed $10^5$.
-----Output-----
For each test case print one integer β the maximum number of teams that you can assemble.
-----Example-----
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0 | t = int(input())
i = 0
while i < t:
n, x = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
n = n - 1
count = 1
ans = 0
while n != -1:
a = arr[n] * count
if a >= x:
ans = ans + 1
count = 1
else:
count = count + 1
n = n - 1
print(ans)
i = i + 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR 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 EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER ASSIGN VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER |
There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $x$.
Each programmer should belong to at most one team. Some programmers may be left without a team.
Calculate the maximum number of teams that you can assemble.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 1000$)Β β the number of test cases.
The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5; 1 \le x \le 10^9$)Β β the number of programmers and the restriction of team skill respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the skill of the $i$-th programmer.
The sum of $n$ over all inputs does not exceed $10^5$.
-----Output-----
For each test case print one integer β the maximum number of teams that you can assemble.
-----Example-----
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0 | from sys import stdin, stdout
def dfs(idx, a, x, memo):
if idx >= len(a):
return 0
if memo[idx] != -1:
return memo[idx]
r = x // a[idx]
if x % a[idx] != 0:
r += 1
r1 = 0
if idx + r - 1 < len(a):
r1 = 1 + dfs(idx + r, a, x, memo)
r2 = dfs(idx + 1, a, x, memo)
memo[idx] = max(r1, r2)
return memo[idx]
def create_the_teams2(n, x, a):
a.sort()
memo = [-1] * n
return dfs(0, a, x, memo)
def create_the_teams(n, x, a):
a.sort(reverse=True)
res = 0
cnt = 0
for i in range(n):
cnt += 1
if a[i] * cnt >= x:
res += 1
cnt = 0
return res
t = int(stdin.readline())
for i in range(t):
n, x = map(int, stdin.readline().split())
a = list(map(int, stdin.readline().split()))
res = create_the_teams(n, x, a)
stdout.write(str(res) + "\n") | FUNC_DEF IF VAR FUNC_CALL VAR VAR RETURN NUMBER IF VAR VAR NUMBER RETURN VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF BIN_OP BIN_OP VAR VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR BIN_OP NUMBER FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR RETURN VAR VAR FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR RETURN FUNC_CALL VAR NUMBER VAR VAR VAR FUNC_DEF EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR 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 FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING |
There are $n$ programmers that you want to split into several non-empty teams. The skill of the $i$-th programmer is $a_i$. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least $x$.
Each programmer should belong to at most one team. Some programmers may be left without a team.
Calculate the maximum number of teams that you can assemble.
-----Input-----
The first line contains the integer $t$ ($1 \le t \le 1000$)Β β the number of test cases.
The first line of each test case contains two integers $n$ and $x$ ($1 \le n \le 10^5; 1 \le x \le 10^9$)Β β the number of programmers and the restriction of team skill respectively.
The second line of each test case contains $n$ integers $a_1, a_2, \dots , a_n$ ($1 \le a_i \le 10^9$), where $a_i$ is the skill of the $i$-th programmer.
The sum of $n$ over all inputs does not exceed $10^5$.
-----Output-----
For each test case print one integer β the maximum number of teams that you can assemble.
-----Example-----
Input
3
5 10
7 11 2 9 5
4 8
2 4 2 3
4 11
1 3 3 7
Output
2
1
0 | from sys import stdin, stdout
for i in range(int(stdin.readline())):
n, x = map(int, stdin.readline().split())
a = [int(num) for num in stdin.readline().split()]
ans, temp = 0, 1
a.sort(), a.reverse()
for i in range(n):
if a[i] * temp >= x:
ans += 1
temp = 0
temp += 1
stdout.write(str(ans) + "\n") | FOR VAR FUNC_CALL 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 NUMBER NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR STRING |
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.
You are to determine the minimum time needed for all n people to get to the office with keys. Assume that people move a unit distance per 1 second. If two people reach a key at the same time, only one of them can take the key. A person can pass through a point with a key without taking it.
-----Input-----
The first line contains three integers n, k and p (1 β€ n β€ 1 000, n β€ k β€ 2 000, 1 β€ p β€ 10^9) β the number of people, the number of keys and the office location.
The second line contains n distinct integers a_1, a_2, ..., a_{n} (1 β€ a_{i} β€ 10^9) β positions in which people are located initially. The positions are given in arbitrary order.
The third line contains k distinct integers b_1, b_2, ..., b_{k} (1 β€ b_{j} β€ 10^9) β positions of the keys. The positions are given in arbitrary order.
Note that there can't be more than one person or more than one key in the same point. A person and a key can be located in the same point.
-----Output-----
Print the minimum time (in seconds) needed for all n to reach the office with keys.
-----Examples-----
Input
2 4 50
20 100
60 10 40 80
Output
50
Input
1 2 10
11
15 7
Output
7
-----Note-----
In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50 seconds. Thus, after 50 seconds everybody is in office with keys. | from sys import stdin, stdout
n, k, p = [int(x) for x in stdin.readline().rstrip().split()]
a = [int(x) for x in stdin.readline().rstrip().split()]
a = sorted(a)
b = [int(x) for x in stdin.readline().rstrip().split()]
b = sorted(b)
ans = int(2000000000.0 + 1)
for i in range(k - n + 1):
tmp = 0
for j in range(n):
tmp = max(tmp, abs(a[j] - b[j + i]) + abs(b[j + i] - p))
ans = min(ans, tmp)
print(ans) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.
You are to determine the minimum time needed for all n people to get to the office with keys. Assume that people move a unit distance per 1 second. If two people reach a key at the same time, only one of them can take the key. A person can pass through a point with a key without taking it.
-----Input-----
The first line contains three integers n, k and p (1 β€ n β€ 1 000, n β€ k β€ 2 000, 1 β€ p β€ 10^9) β the number of people, the number of keys and the office location.
The second line contains n distinct integers a_1, a_2, ..., a_{n} (1 β€ a_{i} β€ 10^9) β positions in which people are located initially. The positions are given in arbitrary order.
The third line contains k distinct integers b_1, b_2, ..., b_{k} (1 β€ b_{j} β€ 10^9) β positions of the keys. The positions are given in arbitrary order.
Note that there can't be more than one person or more than one key in the same point. A person and a key can be located in the same point.
-----Output-----
Print the minimum time (in seconds) needed for all n to reach the office with keys.
-----Examples-----
Input
2 4 50
20 100
60 10 40 80
Output
50
Input
1 2 10
11
15 7
Output
7
-----Note-----
In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50 seconds. Thus, after 50 seconds everybody is in office with keys. | na, nb, o = list(map(int, input().split()))
a = sorted(list(map(int, input().split())))
b = sorted(list(map(int, input().split())))
dp = [[float("inf") for _ in range(nb + 1)] for _ in range(na + 1)]
for i in range(nb + 1):
dp[0][i] = 0
for i in range(1, na + 1):
for j in range(1, nb + 1):
dp[i][j] = min(
dp[i][j - 1],
max(dp[i - 1][j - 1], abs(a[i - 1] - b[j - 1]) + abs(o - b[j - 1])),
)
print(dp[na][nb]) | ASSIGN VAR VAR VAR FUNC_CALL 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR VAR |
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.
You are to determine the minimum time needed for all n people to get to the office with keys. Assume that people move a unit distance per 1 second. If two people reach a key at the same time, only one of them can take the key. A person can pass through a point with a key without taking it.
-----Input-----
The first line contains three integers n, k and p (1 β€ n β€ 1 000, n β€ k β€ 2 000, 1 β€ p β€ 10^9) β the number of people, the number of keys and the office location.
The second line contains n distinct integers a_1, a_2, ..., a_{n} (1 β€ a_{i} β€ 10^9) β positions in which people are located initially. The positions are given in arbitrary order.
The third line contains k distinct integers b_1, b_2, ..., b_{k} (1 β€ b_{j} β€ 10^9) β positions of the keys. The positions are given in arbitrary order.
Note that there can't be more than one person or more than one key in the same point. A person and a key can be located in the same point.
-----Output-----
Print the minimum time (in seconds) needed for all n to reach the office with keys.
-----Examples-----
Input
2 4 50
20 100
60 10 40 80
Output
50
Input
1 2 10
11
15 7
Output
7
-----Note-----
In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50 seconds. Thus, after 50 seconds everybody is in office with keys. | _, _, office = [int(i) for i in input().split()]
people = sorted(int(i) for i in input().split())
keys = sorted(int(i) for i in input().split())
assert len(people) <= len(keys)
min_time = min(
max(
abs(p - keys[ki + v]) + abs(keys[ki + v] - office) for v, p in enumerate(people)
)
for ki in range(len(keys) - len(people) + 1)
)
print(min_time) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR BIN_OP BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.
You are to determine the minimum time needed for all n people to get to the office with keys. Assume that people move a unit distance per 1 second. If two people reach a key at the same time, only one of them can take the key. A person can pass through a point with a key without taking it.
-----Input-----
The first line contains three integers n, k and p (1 β€ n β€ 1 000, n β€ k β€ 2 000, 1 β€ p β€ 10^9) β the number of people, the number of keys and the office location.
The second line contains n distinct integers a_1, a_2, ..., a_{n} (1 β€ a_{i} β€ 10^9) β positions in which people are located initially. The positions are given in arbitrary order.
The third line contains k distinct integers b_1, b_2, ..., b_{k} (1 β€ b_{j} β€ 10^9) β positions of the keys. The positions are given in arbitrary order.
Note that there can't be more than one person or more than one key in the same point. A person and a key can be located in the same point.
-----Output-----
Print the minimum time (in seconds) needed for all n to reach the office with keys.
-----Examples-----
Input
2 4 50
20 100
60 10 40 80
Output
50
Input
1 2 10
11
15 7
Output
7
-----Note-----
In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50 seconds. Thus, after 50 seconds everybody is in office with keys. | pp = list(map(int, input().split()))
inf = int(1e18)
n = pp[0]
k = pp[1]
p = pp[2]
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
dp = [[inf for j in range(0, 2011)] for i in range(0, 1011)]
for i in range(0, k):
dp[0][i] = abs(a[0] - b[i]) + abs(b[i] - p)
for i in range(1, n):
for j in range(0, k):
dp[i][j] = min(
int(dp[i][j]), max(abs(a[i] - b[j]) + abs(b[j] - p), int(dp[i - 1][j - 1]))
)
ans = int(1e18)
for i in range(0, k):
ans = min(ans, int(dp[n - 1][i]))
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR NUMBER NUMBER VAR FUNC_CALL VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER VAR BIN_OP FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR |
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.
You are to determine the minimum time needed for all n people to get to the office with keys. Assume that people move a unit distance per 1 second. If two people reach a key at the same time, only one of them can take the key. A person can pass through a point with a key without taking it.
-----Input-----
The first line contains three integers n, k and p (1 β€ n β€ 1 000, n β€ k β€ 2 000, 1 β€ p β€ 10^9) β the number of people, the number of keys and the office location.
The second line contains n distinct integers a_1, a_2, ..., a_{n} (1 β€ a_{i} β€ 10^9) β positions in which people are located initially. The positions are given in arbitrary order.
The third line contains k distinct integers b_1, b_2, ..., b_{k} (1 β€ b_{j} β€ 10^9) β positions of the keys. The positions are given in arbitrary order.
Note that there can't be more than one person or more than one key in the same point. A person and a key can be located in the same point.
-----Output-----
Print the minimum time (in seconds) needed for all n to reach the office with keys.
-----Examples-----
Input
2 4 50
20 100
60 10 40 80
Output
50
Input
1 2 10
11
15 7
Output
7
-----Note-----
In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50 seconds. Thus, after 50 seconds everybody is in office with keys. | n, k, p = map(int, input().split(" "))
a = [int(x) for x in input().split(" ")]
b = [int(x) for x in input().split(" ")]
a.sort()
b.sort()
result = []
for i in range(k):
max_time = 0
if k - i < n:
break
for ind in range(n):
tem = 0
tem += abs(a[ind] - b[i + ind])
tem += abs(b[i + ind] - p)
if max_time < tem:
max_time = tem
result.append(max_time)
print(min(result)) | ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF BIN_OP VAR VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.
You are to determine the minimum time needed for all n people to get to the office with keys. Assume that people move a unit distance per 1 second. If two people reach a key at the same time, only one of them can take the key. A person can pass through a point with a key without taking it.
-----Input-----
The first line contains three integers n, k and p (1 β€ n β€ 1 000, n β€ k β€ 2 000, 1 β€ p β€ 10^9) β the number of people, the number of keys and the office location.
The second line contains n distinct integers a_1, a_2, ..., a_{n} (1 β€ a_{i} β€ 10^9) β positions in which people are located initially. The positions are given in arbitrary order.
The third line contains k distinct integers b_1, b_2, ..., b_{k} (1 β€ b_{j} β€ 10^9) β positions of the keys. The positions are given in arbitrary order.
Note that there can't be more than one person or more than one key in the same point. A person and a key can be located in the same point.
-----Output-----
Print the minimum time (in seconds) needed for all n to reach the office with keys.
-----Examples-----
Input
2 4 50
20 100
60 10 40 80
Output
50
Input
1 2 10
11
15 7
Output
7
-----Note-----
In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50 seconds. Thus, after 50 seconds everybody is in office with keys. | read = lambda: list(map(int, input().split()))
n, k, p = read()
a = list(read())
b = list(read())
a.sort()
b.sort()
def cal(a, b):
return abs(a - b) + abs(b - p)
mi = 1000000000000000.0
for _ in range(k - n + 1):
ma = 0
for __ in range(n):
te = cal(a[__], b[_ + __])
if te > ma:
ma = te
if ma < mi:
mi = ma
print(mi) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR 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 FUNC_DEF RETURN BIN_OP FUNC_CALL VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR VAR IF VAR VAR ASSIGN VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.
You are to determine the minimum time needed for all n people to get to the office with keys. Assume that people move a unit distance per 1 second. If two people reach a key at the same time, only one of them can take the key. A person can pass through a point with a key without taking it.
-----Input-----
The first line contains three integers n, k and p (1 β€ n β€ 1 000, n β€ k β€ 2 000, 1 β€ p β€ 10^9) β the number of people, the number of keys and the office location.
The second line contains n distinct integers a_1, a_2, ..., a_{n} (1 β€ a_{i} β€ 10^9) β positions in which people are located initially. The positions are given in arbitrary order.
The third line contains k distinct integers b_1, b_2, ..., b_{k} (1 β€ b_{j} β€ 10^9) β positions of the keys. The positions are given in arbitrary order.
Note that there can't be more than one person or more than one key in the same point. A person and a key can be located in the same point.
-----Output-----
Print the minimum time (in seconds) needed for all n to reach the office with keys.
-----Examples-----
Input
2 4 50
20 100
60 10 40 80
Output
50
Input
1 2 10
11
15 7
Output
7
-----Note-----
In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50 seconds. Thus, after 50 seconds everybody is in office with keys. | def dp(k, a, t):
a = sorted(a)
t = sorted(t)
dp = [([float("inf")] * (len(a) + 1)) for i in range(len(t) + 1)]
dp[0][0] = 0
for i in range(len(t)):
for j in range(len(a) + 1):
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
if j < len(a):
dp[i + 1][j + 1] = min(
dp[i + 1][j + 1], max(dp[i][j], abs(a[j] - t[i]) + abs(t[i] - k))
)
return dp[len(t)][len(a)]
a, b, c = map(int, input().strip().split())
lst = list(map(int, input().strip().split()))
lst2 = list(map(int, input().strip().split()))
print(dp(c, lst, lst2)) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR IF VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR RETURN VAR FUNC_CALL VAR 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR |
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.
You are to determine the minimum time needed for all n people to get to the office with keys. Assume that people move a unit distance per 1 second. If two people reach a key at the same time, only one of them can take the key. A person can pass through a point with a key without taking it.
-----Input-----
The first line contains three integers n, k and p (1 β€ n β€ 1 000, n β€ k β€ 2 000, 1 β€ p β€ 10^9) β the number of people, the number of keys and the office location.
The second line contains n distinct integers a_1, a_2, ..., a_{n} (1 β€ a_{i} β€ 10^9) β positions in which people are located initially. The positions are given in arbitrary order.
The third line contains k distinct integers b_1, b_2, ..., b_{k} (1 β€ b_{j} β€ 10^9) β positions of the keys. The positions are given in arbitrary order.
Note that there can't be more than one person or more than one key in the same point. A person and a key can be located in the same point.
-----Output-----
Print the minimum time (in seconds) needed for all n to reach the office with keys.
-----Examples-----
Input
2 4 50
20 100
60 10 40 80
Output
50
Input
1 2 10
11
15 7
Output
7
-----Note-----
In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50 seconds. Thus, after 50 seconds everybody is in office with keys. | def good(n, k, p, a, b, x):
j = 0
c = 0
for i in range(n):
while j < k:
if abs(a[i] - b[j]) + abs(b[j] - p) <= x:
j += 1
c += 1
break
j += 1
return c == n
n, k, p = [int(x) for x in input().split(" ")]
a = [int(x) for x in input().split(" ")]
b = [int(x) for x in input().split(" ")]
a.sort()
b.sort()
l = -1
r = 2 * 10**9
while r - l > 1:
m = (l + r) // 2
if good(n, k, p, a, b, m):
r = m
else:
l = m
print(r) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR IF BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.
You are to determine the minimum time needed for all n people to get to the office with keys. Assume that people move a unit distance per 1 second. If two people reach a key at the same time, only one of them can take the key. A person can pass through a point with a key without taking it.
-----Input-----
The first line contains three integers n, k and p (1 β€ n β€ 1 000, n β€ k β€ 2 000, 1 β€ p β€ 10^9) β the number of people, the number of keys and the office location.
The second line contains n distinct integers a_1, a_2, ..., a_{n} (1 β€ a_{i} β€ 10^9) β positions in which people are located initially. The positions are given in arbitrary order.
The third line contains k distinct integers b_1, b_2, ..., b_{k} (1 β€ b_{j} β€ 10^9) β positions of the keys. The positions are given in arbitrary order.
Note that there can't be more than one person or more than one key in the same point. A person and a key can be located in the same point.
-----Output-----
Print the minimum time (in seconds) needed for all n to reach the office with keys.
-----Examples-----
Input
2 4 50
20 100
60 10 40 80
Output
50
Input
1 2 10
11
15 7
Output
7
-----Note-----
In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50 seconds. Thus, after 50 seconds everybody is in office with keys. | def read():
return [int(x) for x in input().split()]
n, k, p = read()
a = read()
b = read()
a.sort()
b.sort()
ans = 2000000000.0 + 1
ans = int(ans)
for i in range(k - n + 1):
tmp = 0
for j in range(n):
tmp = max(tmp, abs(a[j] - b[i + j]) + abs(b[i + j] - p))
ans = min(ans, tmp)
print(ans) | FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.
You are to determine the minimum time needed for all n people to get to the office with keys. Assume that people move a unit distance per 1 second. If two people reach a key at the same time, only one of them can take the key. A person can pass through a point with a key without taking it.
-----Input-----
The first line contains three integers n, k and p (1 β€ n β€ 1 000, n β€ k β€ 2 000, 1 β€ p β€ 10^9) β the number of people, the number of keys and the office location.
The second line contains n distinct integers a_1, a_2, ..., a_{n} (1 β€ a_{i} β€ 10^9) β positions in which people are located initially. The positions are given in arbitrary order.
The third line contains k distinct integers b_1, b_2, ..., b_{k} (1 β€ b_{j} β€ 10^9) β positions of the keys. The positions are given in arbitrary order.
Note that there can't be more than one person or more than one key in the same point. A person and a key can be located in the same point.
-----Output-----
Print the minimum time (in seconds) needed for all n to reach the office with keys.
-----Examples-----
Input
2 4 50
20 100
60 10 40 80
Output
50
Input
1 2 10
11
15 7
Output
7
-----Note-----
In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50 seconds. Thus, after 50 seconds everybody is in office with keys. | def good(n, k, p, a, b, x):
j = 0
c = 0
for i in range(n):
while j < k:
if abs(a[i] - b[j]) + abs(b[j] - p) <= x:
j += 1
c += 1
break
j += 1
return c == n
n, k, p = [int(x) for x in input().split(" ")]
a = [int(x) for x in input().split(" ")]
b = [int(x) for x in input().split(" ")]
a.sort()
b.sort()
l = -1
r = 2 * 10**9
dp = [([float("inf")] * (n + 1)) for i in range(k + 1)]
dp[0][0] = 0
for i in range(k):
for j in range(n + 1):
dp[i + 1][j] = min(dp[i + 1][j], dp[i][j])
if j < n:
dp[i + 1][j + 1] = min(
dp[i + 1][j + 1], max(dp[i][j], abs(a[j] - b[i]) + abs(b[i] - p))
)
print(dp[k][n]) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR WHILE VAR VAR IF BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER RETURN VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST FUNC_CALL VAR STRING BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR |
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.
You are to determine the minimum time needed for all n people to get to the office with keys. Assume that people move a unit distance per 1 second. If two people reach a key at the same time, only one of them can take the key. A person can pass through a point with a key without taking it.
-----Input-----
The first line contains three integers n, k and p (1 β€ n β€ 1 000, n β€ k β€ 2 000, 1 β€ p β€ 10^9) β the number of people, the number of keys and the office location.
The second line contains n distinct integers a_1, a_2, ..., a_{n} (1 β€ a_{i} β€ 10^9) β positions in which people are located initially. The positions are given in arbitrary order.
The third line contains k distinct integers b_1, b_2, ..., b_{k} (1 β€ b_{j} β€ 10^9) β positions of the keys. The positions are given in arbitrary order.
Note that there can't be more than one person or more than one key in the same point. A person and a key can be located in the same point.
-----Output-----
Print the minimum time (in seconds) needed for all n to reach the office with keys.
-----Examples-----
Input
2 4 50
20 100
60 10 40 80
Output
50
Input
1 2 10
11
15 7
Output
7
-----Note-----
In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50 seconds. Thus, after 50 seconds everybody is in office with keys. | import sys
input = sys.stdin.readline
n, k, p = map(int, input().split())
A = sorted(map(int, input().split()))
B = [0] + sorted(map(int, input().split()))
dp = [([0] * (k + 1)) for _ in range(n + 1)]
for i, a in enumerate(A, 1):
for j in range(k - n + i, i - 1, -1):
dp[i][j] = max(dp[i - 1][j - 1], abs(a - B[j]) + abs(B[j] - p))
print(min(dp[-1][n:])) | IMPORT ASSIGN 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 BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR |
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.
You are to determine the minimum time needed for all n people to get to the office with keys. Assume that people move a unit distance per 1 second. If two people reach a key at the same time, only one of them can take the key. A person can pass through a point with a key without taking it.
-----Input-----
The first line contains three integers n, k and p (1 β€ n β€ 1 000, n β€ k β€ 2 000, 1 β€ p β€ 10^9) β the number of people, the number of keys and the office location.
The second line contains n distinct integers a_1, a_2, ..., a_{n} (1 β€ a_{i} β€ 10^9) β positions in which people are located initially. The positions are given in arbitrary order.
The third line contains k distinct integers b_1, b_2, ..., b_{k} (1 β€ b_{j} β€ 10^9) β positions of the keys. The positions are given in arbitrary order.
Note that there can't be more than one person or more than one key in the same point. A person and a key can be located in the same point.
-----Output-----
Print the minimum time (in seconds) needed for all n to reach the office with keys.
-----Examples-----
Input
2 4 50
20 100
60 10 40 80
Output
50
Input
1 2 10
11
15 7
Output
7
-----Note-----
In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50 seconds. Thus, after 50 seconds everybody is in office with keys. | inf = 10**10
par = [int(i) for i in str(input()).split()]
n, k, p = par[0], par[1], par[2]
person = [int(i) for i in str(input()).split()]
key = [int(i) for i in str(input()).split()]
person = sorted(person)
key = sorted(key)
dp = [[inf for i in range(k)] for j in range(n)]
for i in range(n):
for j in range(k):
if i == 0:
if j == 0:
dp[i][j] = min(dp[i][j], abs(person[i] - key[j]) + abs(p - key[j]))
continue
if i > j:
dp[i][j] = inf
continue
a = dp[i - 1][j - 1] if i > 0 else -1
dp[i][j] = min(dp[i][j - 1], max(a, abs(person[i] - key[j]) + abs(p - key[j])))
print(dp[n - 1][k - 1]) | ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER |
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.
You are to determine the minimum time needed for all n people to get to the office with keys. Assume that people move a unit distance per 1 second. If two people reach a key at the same time, only one of them can take the key. A person can pass through a point with a key without taking it.
-----Input-----
The first line contains three integers n, k and p (1 β€ n β€ 1 000, n β€ k β€ 2 000, 1 β€ p β€ 10^9) β the number of people, the number of keys and the office location.
The second line contains n distinct integers a_1, a_2, ..., a_{n} (1 β€ a_{i} β€ 10^9) β positions in which people are located initially. The positions are given in arbitrary order.
The third line contains k distinct integers b_1, b_2, ..., b_{k} (1 β€ b_{j} β€ 10^9) β positions of the keys. The positions are given in arbitrary order.
Note that there can't be more than one person or more than one key in the same point. A person and a key can be located in the same point.
-----Output-----
Print the minimum time (in seconds) needed for all n to reach the office with keys.
-----Examples-----
Input
2 4 50
20 100
60 10 40 80
Output
50
Input
1 2 10
11
15 7
Output
7
-----Note-----
In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50 seconds. Thus, after 50 seconds everybody is in office with keys. | filler = [0] * 10000
numbers = list(map(int, input().split()))
n = numbers[0]
k = numbers[1]
p = numbers[2]
rezultat = 9999999999999999
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
for i in range(k - n + 1):
temp_max = -999999999
for j in range(n):
temp_max = max(abs(b[i + j] - a[j]) + abs(b[i + j] - p), temp_max)
rezultat = min(temp_max, rezultat)
print(rezultat) | ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN 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 EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.
You are to determine the minimum time needed for all n people to get to the office with keys. Assume that people move a unit distance per 1 second. If two people reach a key at the same time, only one of them can take the key. A person can pass through a point with a key without taking it.
-----Input-----
The first line contains three integers n, k and p (1 β€ n β€ 1 000, n β€ k β€ 2 000, 1 β€ p β€ 10^9) β the number of people, the number of keys and the office location.
The second line contains n distinct integers a_1, a_2, ..., a_{n} (1 β€ a_{i} β€ 10^9) β positions in which people are located initially. The positions are given in arbitrary order.
The third line contains k distinct integers b_1, b_2, ..., b_{k} (1 β€ b_{j} β€ 10^9) β positions of the keys. The positions are given in arbitrary order.
Note that there can't be more than one person or more than one key in the same point. A person and a key can be located in the same point.
-----Output-----
Print the minimum time (in seconds) needed for all n to reach the office with keys.
-----Examples-----
Input
2 4 50
20 100
60 10 40 80
Output
50
Input
1 2 10
11
15 7
Output
7
-----Note-----
In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50 seconds. Thus, after 50 seconds everybody is in office with keys. | s = input()
n, k, p = s.split(" ")
n = int(n)
k = int(k)
p = int(p)
def time(start):
global people, keys, n, p
res = 0
for i in range(n):
res = max(res, abs(people[i] - keys[i + start]) + abs(keys[i + start] - p))
return res
s = input()
people = s.split(" ")
for i in range(n):
people[i] = int(people[i])
s = input()
keys = s.split(" ")
for i in range(k):
keys[i] = int(keys[i])
people.sort()
keys.sort()
res = 10**10
for i in range(k - n + 1):
res = min(res, time(i))
print(res) | ASSIGN VAR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR |
There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebody, it couldn't be taken by anybody else.
You are to determine the minimum time needed for all n people to get to the office with keys. Assume that people move a unit distance per 1 second. If two people reach a key at the same time, only one of them can take the key. A person can pass through a point with a key without taking it.
-----Input-----
The first line contains three integers n, k and p (1 β€ n β€ 1 000, n β€ k β€ 2 000, 1 β€ p β€ 10^9) β the number of people, the number of keys and the office location.
The second line contains n distinct integers a_1, a_2, ..., a_{n} (1 β€ a_{i} β€ 10^9) β positions in which people are located initially. The positions are given in arbitrary order.
The third line contains k distinct integers b_1, b_2, ..., b_{k} (1 β€ b_{j} β€ 10^9) β positions of the keys. The positions are given in arbitrary order.
Note that there can't be more than one person or more than one key in the same point. A person and a key can be located in the same point.
-----Output-----
Print the minimum time (in seconds) needed for all n to reach the office with keys.
-----Examples-----
Input
2 4 50
20 100
60 10 40 80
Output
50
Input
1 2 10
11
15 7
Output
7
-----Note-----
In the first example the person located at point 20 should take the key located at point 40 and go with it to the office located at point 50. He spends 30 seconds. The person located at point 100 can take the key located at point 80 and go to the office with it. He spends 50 seconds. Thus, after 50 seconds everybody is in office with keys. | def check(x):
j = 0
for i in range(n):
if j >= k:
return False
while abs(b[j] - a[i]) + abs(b[j] - p) > x:
j += 1
if j >= k:
return False
j += 1
return True
n, k, p = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
a.sort()
b.sort()
l = 0
r = 10**18
ans = -1
while l <= r:
mid = l + (r - l) // 2
if check(mid):
r = mid - 1
ans = mid
else:
l = mid + 1
print(ans) | FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER WHILE BIN_OP FUNC_CALL VAR BIN_OP VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER IF VAR VAR RETURN NUMBER VAR NUMBER RETURN 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are n squirrel(s) waiting below the feet of m chestnut tree(s). The first chestnut of the i-th tree will fall right after T_{i} second(s), and one more every P_{i} second(s) after that. The βbig mamaβ of squirrels wants them to bring their nest no less than k chestnuts to avoid the big storm coming, as fast as possible! So they are discussing to wait below which trees to take enough chestnuts in the shortest time. Time to move to the positions is zero, and the squirrels move nowhere after that.
------ Request ------
Calculate the shortest time (how many seconds more) the squirrels can take enough chestnuts.
------ Input ------
The first line contains an integer t, the number of test cases, for each:
The first line contains the integers m,n,k, respectively.
The second line contains the integers T_{i} (i=1..m), respectively.
The third line contains the integers P_{i} (i=1..m), respectively.
(Each integer on a same line is separated by at least one space character, there is no added line between test cases)
------ Output ------
For each test cases, output in a single line an integer which is the shortest time calculated.
------ Limitations ------
0
0
07
0i,P_{i}β€100
----- Sample Input 1 ------
2
3 2 5
5 1 2
1 2 1
3 2 5
5 1 2
1 1 1
----- Sample Output 1 ------
4
3
----- explanation 1 ------
Test case $1$: Two squirrels wait below trees $2$ and $3$.
- After $1$ second, a chestnut from tree $2$ falls. Total chestnuts the squirrels have is $1$.
- After $2$ seconds, a chestnut from tree $3$ falls. Total chestnuts the squirrels have is $2$.
- After $3$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $4$.
- After $4$ seconds, a chestnut from tree $3$ falls. Total chestnuts the squirrels have is $5$.
Total time to gather $5$ chestnuts is $5$ seconds.
Test case $2$: Two squirrels wait below trees $2$ and $3$.
- After $1$ second, a chestnut from tree $2$ falls. Total chestnuts the squirrels have is $1$.
- After $2$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $3$.
- After $3$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $5$.
Total time to gather $5$ chestnuts is $3$ seconds. | def solve(time):
s, e = 1, 10**9
ans = 0
while s <= e:
mid = (s + e) // 2
nuts = 0
temp = []
for i in range(m):
if mid - time[i][0] < 0:
temp.append(0)
continue
temp.append(1 + (mid - time[i][0]) // time[i][1])
temp.sort(reverse=True)
nuts = sum(temp[: min(n, m)])
if nuts >= k:
ans = mid
e = mid - 1
else:
s = mid + 1
print(ans)
for _ in range(int(input())):
m, n, k = list(map(int, input().split()))
t = list(map(int, input().split()))
tp = list(map(int, input().split()))
time = list(map(list, zip(t, tp)))
solve(time) | FUNC_DEF ASSIGN VAR VAR NUMBER BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR 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 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
There are n squirrel(s) waiting below the feet of m chestnut tree(s). The first chestnut of the i-th tree will fall right after T_{i} second(s), and one more every P_{i} second(s) after that. The βbig mamaβ of squirrels wants them to bring their nest no less than k chestnuts to avoid the big storm coming, as fast as possible! So they are discussing to wait below which trees to take enough chestnuts in the shortest time. Time to move to the positions is zero, and the squirrels move nowhere after that.
------ Request ------
Calculate the shortest time (how many seconds more) the squirrels can take enough chestnuts.
------ Input ------
The first line contains an integer t, the number of test cases, for each:
The first line contains the integers m,n,k, respectively.
The second line contains the integers T_{i} (i=1..m), respectively.
The third line contains the integers P_{i} (i=1..m), respectively.
(Each integer on a same line is separated by at least one space character, there is no added line between test cases)
------ Output ------
For each test cases, output in a single line an integer which is the shortest time calculated.
------ Limitations ------
0
0
07
0i,P_{i}β€100
----- Sample Input 1 ------
2
3 2 5
5 1 2
1 2 1
3 2 5
5 1 2
1 1 1
----- Sample Output 1 ------
4
3
----- explanation 1 ------
Test case $1$: Two squirrels wait below trees $2$ and $3$.
- After $1$ second, a chestnut from tree $2$ falls. Total chestnuts the squirrels have is $1$.
- After $2$ seconds, a chestnut from tree $3$ falls. Total chestnuts the squirrels have is $2$.
- After $3$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $4$.
- After $4$ seconds, a chestnut from tree $3$ falls. Total chestnuts the squirrels have is $5$.
Total time to gather $5$ chestnuts is $5$ seconds.
Test case $2$: Two squirrels wait below trees $2$ and $3$.
- After $1$ second, a chestnut from tree $2$ falls. Total chestnuts the squirrels have is $1$.
- After $2$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $3$.
- After $3$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $5$.
Total time to gather $5$ chestnuts is $3$ seconds. | def sol():
l = 0
r = 10**9
final = 0
while l <= r:
mid = (l + r) // 2
ans = [0] * m
for i in range(m):
ans[i] = max(0, (mid - t[i]) // p[i] + 1)
ans.sort(reverse=True)
x = sum(ans[0:n])
if x >= k:
r = mid - 1
final = mid
else:
l = mid + 1
print(final)
for i in range(int(input())):
m, n, k = [int(x) for x in input().split()]
t = [int(x) for x in input().split()]
p = [int(x) for x in input().split()]
sol() | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR NUMBER BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL 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 ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR |
There are n squirrel(s) waiting below the feet of m chestnut tree(s). The first chestnut of the i-th tree will fall right after T_{i} second(s), and one more every P_{i} second(s) after that. The βbig mamaβ of squirrels wants them to bring their nest no less than k chestnuts to avoid the big storm coming, as fast as possible! So they are discussing to wait below which trees to take enough chestnuts in the shortest time. Time to move to the positions is zero, and the squirrels move nowhere after that.
------ Request ------
Calculate the shortest time (how many seconds more) the squirrels can take enough chestnuts.
------ Input ------
The first line contains an integer t, the number of test cases, for each:
The first line contains the integers m,n,k, respectively.
The second line contains the integers T_{i} (i=1..m), respectively.
The third line contains the integers P_{i} (i=1..m), respectively.
(Each integer on a same line is separated by at least one space character, there is no added line between test cases)
------ Output ------
For each test cases, output in a single line an integer which is the shortest time calculated.
------ Limitations ------
0
0
07
0i,P_{i}β€100
----- Sample Input 1 ------
2
3 2 5
5 1 2
1 2 1
3 2 5
5 1 2
1 1 1
----- Sample Output 1 ------
4
3
----- explanation 1 ------
Test case $1$: Two squirrels wait below trees $2$ and $3$.
- After $1$ second, a chestnut from tree $2$ falls. Total chestnuts the squirrels have is $1$.
- After $2$ seconds, a chestnut from tree $3$ falls. Total chestnuts the squirrels have is $2$.
- After $3$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $4$.
- After $4$ seconds, a chestnut from tree $3$ falls. Total chestnuts the squirrels have is $5$.
Total time to gather $5$ chestnuts is $5$ seconds.
Test case $2$: Two squirrels wait below trees $2$ and $3$.
- After $1$ second, a chestnut from tree $2$ falls. Total chestnuts the squirrels have is $1$.
- After $2$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $3$.
- After $3$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $5$.
Total time to gather $5$ chestnuts is $3$ seconds. | for _ in range(int(input())):
m, n, k = map(int, input().split())
t = list(map(int, input().split()))
p = list(map(int, input().split()))
start = 0
end = 10**9
res = 0
while start <= end:
sum1 = [0] * m
mid = start + (end - start) // 2
for i in range(m):
sum1[i] = max((mid - t[i]) // p[i] + 1, 0)
sum1.sort(reverse=True)
val = sum(sum1[:n])
if val >= k:
end = mid - 1
res = mid
else:
start = mid + 1
print(res) | 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are n squirrel(s) waiting below the feet of m chestnut tree(s). The first chestnut of the i-th tree will fall right after T_{i} second(s), and one more every P_{i} second(s) after that. The βbig mamaβ of squirrels wants them to bring their nest no less than k chestnuts to avoid the big storm coming, as fast as possible! So they are discussing to wait below which trees to take enough chestnuts in the shortest time. Time to move to the positions is zero, and the squirrels move nowhere after that.
------ Request ------
Calculate the shortest time (how many seconds more) the squirrels can take enough chestnuts.
------ Input ------
The first line contains an integer t, the number of test cases, for each:
The first line contains the integers m,n,k, respectively.
The second line contains the integers T_{i} (i=1..m), respectively.
The third line contains the integers P_{i} (i=1..m), respectively.
(Each integer on a same line is separated by at least one space character, there is no added line between test cases)
------ Output ------
For each test cases, output in a single line an integer which is the shortest time calculated.
------ Limitations ------
0
0
07
0i,P_{i}β€100
----- Sample Input 1 ------
2
3 2 5
5 1 2
1 2 1
3 2 5
5 1 2
1 1 1
----- Sample Output 1 ------
4
3
----- explanation 1 ------
Test case $1$: Two squirrels wait below trees $2$ and $3$.
- After $1$ second, a chestnut from tree $2$ falls. Total chestnuts the squirrels have is $1$.
- After $2$ seconds, a chestnut from tree $3$ falls. Total chestnuts the squirrels have is $2$.
- After $3$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $4$.
- After $4$ seconds, a chestnut from tree $3$ falls. Total chestnuts the squirrels have is $5$.
Total time to gather $5$ chestnuts is $5$ seconds.
Test case $2$: Two squirrels wait below trees $2$ and $3$.
- After $1$ second, a chestnut from tree $2$ falls. Total chestnuts the squirrels have is $1$.
- After $2$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $3$.
- After $3$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $5$.
Total time to gather $5$ chestnuts is $3$ seconds. | for _ in range(int(input())):
m, n, k = map(int, input().split())
T = list(map(int, input().split()))
P = list(map(int, input().split()))
t_min = 0
t_max = 10000000
t_ans = 0
while t_min <= t_max:
t_mid = (t_min + t_max) // 2
fa = [((t_mid - T[i]) // P[i] + 1) for i in range(m) if t_mid >= T[i]]
fm = sum(sorted(fa, reverse=True)[:n])
if fm < k:
t_min = t_mid + 1
else:
t_max = t_mid - 1
if fm >= k:
t_ans = t_mid
print(t_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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
There are n squirrel(s) waiting below the feet of m chestnut tree(s). The first chestnut of the i-th tree will fall right after T_{i} second(s), and one more every P_{i} second(s) after that. The βbig mamaβ of squirrels wants them to bring their nest no less than k chestnuts to avoid the big storm coming, as fast as possible! So they are discussing to wait below which trees to take enough chestnuts in the shortest time. Time to move to the positions is zero, and the squirrels move nowhere after that.
------ Request ------
Calculate the shortest time (how many seconds more) the squirrels can take enough chestnuts.
------ Input ------
The first line contains an integer t, the number of test cases, for each:
The first line contains the integers m,n,k, respectively.
The second line contains the integers T_{i} (i=1..m), respectively.
The third line contains the integers P_{i} (i=1..m), respectively.
(Each integer on a same line is separated by at least one space character, there is no added line between test cases)
------ Output ------
For each test cases, output in a single line an integer which is the shortest time calculated.
------ Limitations ------
0
0
07
0i,P_{i}β€100
----- Sample Input 1 ------
2
3 2 5
5 1 2
1 2 1
3 2 5
5 1 2
1 1 1
----- Sample Output 1 ------
4
3
----- explanation 1 ------
Test case $1$: Two squirrels wait below trees $2$ and $3$.
- After $1$ second, a chestnut from tree $2$ falls. Total chestnuts the squirrels have is $1$.
- After $2$ seconds, a chestnut from tree $3$ falls. Total chestnuts the squirrels have is $2$.
- After $3$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $4$.
- After $4$ seconds, a chestnut from tree $3$ falls. Total chestnuts the squirrels have is $5$.
Total time to gather $5$ chestnuts is $5$ seconds.
Test case $2$: Two squirrels wait below trees $2$ and $3$.
- After $1$ second, a chestnut from tree $2$ falls. Total chestnuts the squirrels have is $1$.
- After $2$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $3$.
- After $3$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $5$.
Total time to gather $5$ chestnuts is $3$ seconds. | def f(time):
l = [((time - T[i]) // P[i] + 1) for i in range(m) if time >= T[i]]
return sum(sorted(l, reverse=True)[:n])
t = int(input())
for _ in range(t):
m, n, k = map(int, input().split())
T = [int(_) for _ in input().split()]
P = [int(_) for _ in input().split()]
t_min = 0
t_max = 10000000
t_ans = 0
while t_min <= t_max:
t_mid = (t_min + t_max) // 2
fm = f(t_mid)
if fm < k:
t_min = t_mid + 1
else:
t_max = t_mid - 1
if fm >= k:
t_ans = t_mid
print(t_ans) | FUNC_DEF ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR VAR VAR VAR RETURN FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER 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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN 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 BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
There are n squirrel(s) waiting below the feet of m chestnut tree(s). The first chestnut of the i-th tree will fall right after T_{i} second(s), and one more every P_{i} second(s) after that. The βbig mamaβ of squirrels wants them to bring their nest no less than k chestnuts to avoid the big storm coming, as fast as possible! So they are discussing to wait below which trees to take enough chestnuts in the shortest time. Time to move to the positions is zero, and the squirrels move nowhere after that.
------ Request ------
Calculate the shortest time (how many seconds more) the squirrels can take enough chestnuts.
------ Input ------
The first line contains an integer t, the number of test cases, for each:
The first line contains the integers m,n,k, respectively.
The second line contains the integers T_{i} (i=1..m), respectively.
The third line contains the integers P_{i} (i=1..m), respectively.
(Each integer on a same line is separated by at least one space character, there is no added line between test cases)
------ Output ------
For each test cases, output in a single line an integer which is the shortest time calculated.
------ Limitations ------
0
0
07
0i,P_{i}β€100
----- Sample Input 1 ------
2
3 2 5
5 1 2
1 2 1
3 2 5
5 1 2
1 1 1
----- Sample Output 1 ------
4
3
----- explanation 1 ------
Test case $1$: Two squirrels wait below trees $2$ and $3$.
- After $1$ second, a chestnut from tree $2$ falls. Total chestnuts the squirrels have is $1$.
- After $2$ seconds, a chestnut from tree $3$ falls. Total chestnuts the squirrels have is $2$.
- After $3$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $4$.
- After $4$ seconds, a chestnut from tree $3$ falls. Total chestnuts the squirrels have is $5$.
Total time to gather $5$ chestnuts is $5$ seconds.
Test case $2$: Two squirrels wait below trees $2$ and $3$.
- After $1$ second, a chestnut from tree $2$ falls. Total chestnuts the squirrels have is $1$.
- After $2$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $3$.
- After $3$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $5$.
Total time to gather $5$ chestnuts is $3$ seconds. | t = int(input())
for k in range(t):
m, n, k = input().split()
m, n, k = int(m), int(n), int(k)
s_t = input().split()
s_p = input().split()
arr_t = []
arr_p = []
for i in range(m):
arr_t.append(int(s_t[i]))
arr_p.append(int(s_p[i]))
l = 0
r = arr_t[0] + (k - 1) * arr_p[0]
mn = r
while l <= r:
mid = l + (r - l) // 2
if mid >= mn:
r = mid - 1
else:
arr = []
s = 0
for i in range(m):
if mid < arr_t[i]:
arr.append(0)
else:
arr.append(1 + (mid - arr_t[i]) // arr_p[i])
s += arr[i]
if n >= m:
if s >= k:
mn = mid
r = mid - 1
else:
l = mid + 1
continue
arr.sort(reverse=True)
s = 0
rem = n
for i in range(m):
if rem > 0:
s += arr[i]
rem -= 1
if rem == 0:
break
if s >= k:
mn = mid
r = mid - 1
else:
l = mid + 1
print(mn) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR IF VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR NUMBER IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are n squirrel(s) waiting below the feet of m chestnut tree(s). The first chestnut of the i-th tree will fall right after T_{i} second(s), and one more every P_{i} second(s) after that. The βbig mamaβ of squirrels wants them to bring their nest no less than k chestnuts to avoid the big storm coming, as fast as possible! So they are discussing to wait below which trees to take enough chestnuts in the shortest time. Time to move to the positions is zero, and the squirrels move nowhere after that.
------ Request ------
Calculate the shortest time (how many seconds more) the squirrels can take enough chestnuts.
------ Input ------
The first line contains an integer t, the number of test cases, for each:
The first line contains the integers m,n,k, respectively.
The second line contains the integers T_{i} (i=1..m), respectively.
The third line contains the integers P_{i} (i=1..m), respectively.
(Each integer on a same line is separated by at least one space character, there is no added line between test cases)
------ Output ------
For each test cases, output in a single line an integer which is the shortest time calculated.
------ Limitations ------
0
0
07
0i,P_{i}β€100
----- Sample Input 1 ------
2
3 2 5
5 1 2
1 2 1
3 2 5
5 1 2
1 1 1
----- Sample Output 1 ------
4
3
----- explanation 1 ------
Test case $1$: Two squirrels wait below trees $2$ and $3$.
- After $1$ second, a chestnut from tree $2$ falls. Total chestnuts the squirrels have is $1$.
- After $2$ seconds, a chestnut from tree $3$ falls. Total chestnuts the squirrels have is $2$.
- After $3$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $4$.
- After $4$ seconds, a chestnut from tree $3$ falls. Total chestnuts the squirrels have is $5$.
Total time to gather $5$ chestnuts is $5$ seconds.
Test case $2$: Two squirrels wait below trees $2$ and $3$.
- After $1$ second, a chestnut from tree $2$ falls. Total chestnuts the squirrels have is $1$.
- After $2$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $3$.
- After $3$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $5$.
Total time to gather $5$ chestnuts is $3$ seconds. | def soln(m, n, k, t, p):
low = 0
res = high = 10**9
while low <= high:
time = (low + high) // 2
cur = []
for i in range(m):
cur.append(max((time - t[i]) // p[i] + 1, 0))
nuts = sum(sorted(cur, reverse=True)[:n])
if nuts < k:
low = time + 1
else:
high = time - 1
res = time
return res
for _ in range(int(input())):
m, n, k = map(int, input().split())
t = list(map(int, input().split()))
p = list(map(int, input().split()))
print(soln(m, n, k, t, p)) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR RETURN 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 FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR VAR VAR |
There are n squirrel(s) waiting below the feet of m chestnut tree(s). The first chestnut of the i-th tree will fall right after T_{i} second(s), and one more every P_{i} second(s) after that. The βbig mamaβ of squirrels wants them to bring their nest no less than k chestnuts to avoid the big storm coming, as fast as possible! So they are discussing to wait below which trees to take enough chestnuts in the shortest time. Time to move to the positions is zero, and the squirrels move nowhere after that.
------ Request ------
Calculate the shortest time (how many seconds more) the squirrels can take enough chestnuts.
------ Input ------
The first line contains an integer t, the number of test cases, for each:
The first line contains the integers m,n,k, respectively.
The second line contains the integers T_{i} (i=1..m), respectively.
The third line contains the integers P_{i} (i=1..m), respectively.
(Each integer on a same line is separated by at least one space character, there is no added line between test cases)
------ Output ------
For each test cases, output in a single line an integer which is the shortest time calculated.
------ Limitations ------
0
0
07
0i,P_{i}β€100
----- Sample Input 1 ------
2
3 2 5
5 1 2
1 2 1
3 2 5
5 1 2
1 1 1
----- Sample Output 1 ------
4
3
----- explanation 1 ------
Test case $1$: Two squirrels wait below trees $2$ and $3$.
- After $1$ second, a chestnut from tree $2$ falls. Total chestnuts the squirrels have is $1$.
- After $2$ seconds, a chestnut from tree $3$ falls. Total chestnuts the squirrels have is $2$.
- After $3$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $4$.
- After $4$ seconds, a chestnut from tree $3$ falls. Total chestnuts the squirrels have is $5$.
Total time to gather $5$ chestnuts is $5$ seconds.
Test case $2$: Two squirrels wait below trees $2$ and $3$.
- After $1$ second, a chestnut from tree $2$ falls. Total chestnuts the squirrels have is $1$.
- After $2$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $3$.
- After $3$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $5$.
Total time to gather $5$ chestnuts is $3$ seconds. | def check(t):
chestnuts = []
for el in arr:
chestnuts.append((t - el[0]) // el[1] + 1)
chestnuts.sort(reverse=True)
if sum(chestnuts[:n]) >= k:
return True
else:
return False
t = int(input())
for i in range(t):
length, n, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
arr = [[a[i], b[i]] for i in range(length)]
r = 1000000000000
l = 0
ans = 1000000000000
while r >= l:
m = (l + r) // 2
if check(m):
r = m - 1
ans = min(ans, m)
else:
l = m + 1
print(l) | FUNC_DEF ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR RETURN NUMBER RETURN 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER 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 FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are n squirrel(s) waiting below the feet of m chestnut tree(s). The first chestnut of the i-th tree will fall right after T_{i} second(s), and one more every P_{i} second(s) after that. The βbig mamaβ of squirrels wants them to bring their nest no less than k chestnuts to avoid the big storm coming, as fast as possible! So they are discussing to wait below which trees to take enough chestnuts in the shortest time. Time to move to the positions is zero, and the squirrels move nowhere after that.
------ Request ------
Calculate the shortest time (how many seconds more) the squirrels can take enough chestnuts.
------ Input ------
The first line contains an integer t, the number of test cases, for each:
The first line contains the integers m,n,k, respectively.
The second line contains the integers T_{i} (i=1..m), respectively.
The third line contains the integers P_{i} (i=1..m), respectively.
(Each integer on a same line is separated by at least one space character, there is no added line between test cases)
------ Output ------
For each test cases, output in a single line an integer which is the shortest time calculated.
------ Limitations ------
0
0
07
0i,P_{i}β€100
----- Sample Input 1 ------
2
3 2 5
5 1 2
1 2 1
3 2 5
5 1 2
1 1 1
----- Sample Output 1 ------
4
3
----- explanation 1 ------
Test case $1$: Two squirrels wait below trees $2$ and $3$.
- After $1$ second, a chestnut from tree $2$ falls. Total chestnuts the squirrels have is $1$.
- After $2$ seconds, a chestnut from tree $3$ falls. Total chestnuts the squirrels have is $2$.
- After $3$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $4$.
- After $4$ seconds, a chestnut from tree $3$ falls. Total chestnuts the squirrels have is $5$.
Total time to gather $5$ chestnuts is $5$ seconds.
Test case $2$: Two squirrels wait below trees $2$ and $3$.
- After $1$ second, a chestnut from tree $2$ falls. Total chestnuts the squirrels have is $1$.
- After $2$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $3$.
- After $3$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $5$.
Total time to gather $5$ chestnuts is $3$ seconds. | t = int(input())
for _ in range(t):
m, n, k = map(int, input().split())
t = [int(item) for item in input().split()]
p = [int(item) for item in input().split()]
low = 0
high = 10**5 + 105
ans = 0
while low <= high:
arr = [0] * m
mid = low + (high - low) // 2
for i in range(m):
if mid < t[i]:
arr[i] = 0
arr[i] = 1 + (mid - t[i]) // p[i]
arr.sort(reverse=True)
temp = 0
for i in range(min(m, n)):
temp += arr[i]
if temp >= k:
ans = mid
high = mid - 1
else:
low = mid + 1
print(ans) | 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 VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR 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 |
There are n squirrel(s) waiting below the feet of m chestnut tree(s). The first chestnut of the i-th tree will fall right after T_{i} second(s), and one more every P_{i} second(s) after that. The βbig mamaβ of squirrels wants them to bring their nest no less than k chestnuts to avoid the big storm coming, as fast as possible! So they are discussing to wait below which trees to take enough chestnuts in the shortest time. Time to move to the positions is zero, and the squirrels move nowhere after that.
------ Request ------
Calculate the shortest time (how many seconds more) the squirrels can take enough chestnuts.
------ Input ------
The first line contains an integer t, the number of test cases, for each:
The first line contains the integers m,n,k, respectively.
The second line contains the integers T_{i} (i=1..m), respectively.
The third line contains the integers P_{i} (i=1..m), respectively.
(Each integer on a same line is separated by at least one space character, there is no added line between test cases)
------ Output ------
For each test cases, output in a single line an integer which is the shortest time calculated.
------ Limitations ------
0
0
07
0i,P_{i}β€100
----- Sample Input 1 ------
2
3 2 5
5 1 2
1 2 1
3 2 5
5 1 2
1 1 1
----- Sample Output 1 ------
4
3
----- explanation 1 ------
Test case $1$: Two squirrels wait below trees $2$ and $3$.
- After $1$ second, a chestnut from tree $2$ falls. Total chestnuts the squirrels have is $1$.
- After $2$ seconds, a chestnut from tree $3$ falls. Total chestnuts the squirrels have is $2$.
- After $3$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $4$.
- After $4$ seconds, a chestnut from tree $3$ falls. Total chestnuts the squirrels have is $5$.
Total time to gather $5$ chestnuts is $5$ seconds.
Test case $2$: Two squirrels wait below trees $2$ and $3$.
- After $1$ second, a chestnut from tree $2$ falls. Total chestnuts the squirrels have is $1$.
- After $2$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $3$.
- After $3$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $5$.
Total time to gather $5$ chestnuts is $3$ seconds. | def BinarySearch():
left = 0
right = 10**9 + 101
res = 0
while left <= right:
Sum = [0] * m
mid = (left + right) // 2
for i in range(m):
Sum[i] = max((mid - t[i]) // p[i] + 1, 0)
Sum.sort(reverse=True)
x = sum(Sum[0:n])
if x >= k:
right = mid - 1
res = mid
else:
left = mid + 1
return res
a = int(input())
while a != 0:
a -= 1
m, n, k = map(int, input().split())
t = list(map(int, input().split()))
p = list(map(int, input().split()))
print(BinarySearch()) | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR NUMBER VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER 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 ASSIGN 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 FUNC_CALL VAR |
There are n squirrel(s) waiting below the feet of m chestnut tree(s). The first chestnut of the i-th tree will fall right after T_{i} second(s), and one more every P_{i} second(s) after that. The βbig mamaβ of squirrels wants them to bring their nest no less than k chestnuts to avoid the big storm coming, as fast as possible! So they are discussing to wait below which trees to take enough chestnuts in the shortest time. Time to move to the positions is zero, and the squirrels move nowhere after that.
------ Request ------
Calculate the shortest time (how many seconds more) the squirrels can take enough chestnuts.
------ Input ------
The first line contains an integer t, the number of test cases, for each:
The first line contains the integers m,n,k, respectively.
The second line contains the integers T_{i} (i=1..m), respectively.
The third line contains the integers P_{i} (i=1..m), respectively.
(Each integer on a same line is separated by at least one space character, there is no added line between test cases)
------ Output ------
For each test cases, output in a single line an integer which is the shortest time calculated.
------ Limitations ------
0
0
07
0i,P_{i}β€100
----- Sample Input 1 ------
2
3 2 5
5 1 2
1 2 1
3 2 5
5 1 2
1 1 1
----- Sample Output 1 ------
4
3
----- explanation 1 ------
Test case $1$: Two squirrels wait below trees $2$ and $3$.
- After $1$ second, a chestnut from tree $2$ falls. Total chestnuts the squirrels have is $1$.
- After $2$ seconds, a chestnut from tree $3$ falls. Total chestnuts the squirrels have is $2$.
- After $3$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $4$.
- After $4$ seconds, a chestnut from tree $3$ falls. Total chestnuts the squirrels have is $5$.
Total time to gather $5$ chestnuts is $5$ seconds.
Test case $2$: Two squirrels wait below trees $2$ and $3$.
- After $1$ second, a chestnut from tree $2$ falls. Total chestnuts the squirrels have is $1$.
- After $2$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $3$.
- After $3$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $5$.
Total time to gather $5$ chestnuts is $3$ seconds. | def compute(t, p, m, mid):
ans = []
for i in range(len(t)):
v = 0
if t[i] <= mid:
v = 1 + (mid - t[i]) // p[i]
ans.append(v)
ans.sort()
ans.reverse()
ans = ans[:m]
return sum(ans)
t = int(input())
for _ in range(t):
m, n, k = map(int, input().split())
t = list(map(int, input().split()))
p = list(map(int, input().split()))
tm = 2**32 - 1
for i in range(m):
tm = min(tm, t[i] + p[i] * (k - 1))
st, en = 0, tm
while st < en:
mid = (st + en) // 2
curr = compute(t, p, n, mid)
if curr < k:
st = mid + 1
else:
en = mid
i = en - 1
while compute(t, p, n, i) < k:
i += 1
print(i) | FUNC_DEF ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR RETURN FUNC_CALL 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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR |
There are n squirrel(s) waiting below the feet of m chestnut tree(s). The first chestnut of the i-th tree will fall right after T_{i} second(s), and one more every P_{i} second(s) after that. The βbig mamaβ of squirrels wants them to bring their nest no less than k chestnuts to avoid the big storm coming, as fast as possible! So they are discussing to wait below which trees to take enough chestnuts in the shortest time. Time to move to the positions is zero, and the squirrels move nowhere after that.
------ Request ------
Calculate the shortest time (how many seconds more) the squirrels can take enough chestnuts.
------ Input ------
The first line contains an integer t, the number of test cases, for each:
The first line contains the integers m,n,k, respectively.
The second line contains the integers T_{i} (i=1..m), respectively.
The third line contains the integers P_{i} (i=1..m), respectively.
(Each integer on a same line is separated by at least one space character, there is no added line between test cases)
------ Output ------
For each test cases, output in a single line an integer which is the shortest time calculated.
------ Limitations ------
0
0
07
0i,P_{i}β€100
----- Sample Input 1 ------
2
3 2 5
5 1 2
1 2 1
3 2 5
5 1 2
1 1 1
----- Sample Output 1 ------
4
3
----- explanation 1 ------
Test case $1$: Two squirrels wait below trees $2$ and $3$.
- After $1$ second, a chestnut from tree $2$ falls. Total chestnuts the squirrels have is $1$.
- After $2$ seconds, a chestnut from tree $3$ falls. Total chestnuts the squirrels have is $2$.
- After $3$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $4$.
- After $4$ seconds, a chestnut from tree $3$ falls. Total chestnuts the squirrels have is $5$.
Total time to gather $5$ chestnuts is $5$ seconds.
Test case $2$: Two squirrels wait below trees $2$ and $3$.
- After $1$ second, a chestnut from tree $2$ falls. Total chestnuts the squirrels have is $1$.
- After $2$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $3$.
- After $3$ seconds, two chestnuts fall from trees $2$ and $3$. Total chestnuts the squirrels have is $5$.
Total time to gather $5$ chestnuts is $3$ seconds. | from sys import stdin
for _ in range(int(stdin.readline())):
m, n, k = map(int, stdin.readline().split())
first = list(map(int, stdin.readline().split()))
second = list(map(int, stdin.readline().split()))
time = list(map(list, zip(first, second)))
low = 1
high = 10**9
ans = 10**9
while low <= high:
mid = (high + low) // 2
nuts = []
for i in time:
if i[0] > mid:
nuts.append(0)
else:
nuts.append(1 + (mid - i[0]) // i[1])
nuts.sort(reverse=True)
get = sum(nuts[: min(n, m)])
if get >= k:
ans = mid
high = mid - 1
else:
low = mid + 1
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 ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR BIN_OP NUMBER BIN_OP BIN_OP VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR 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 |
Dilpreet wants to paint his dog's home that has n boards with different lengths. The length of i^{th }board is given by arr[i] where arr[] is an array of n integers. He hired k painters for this work and each painter takes 1 unit time to paint 1 unit of the board.
The problem is to find the minimum time to get this job done if all painters start together with the constraint that any painter will only paint continuous boards, say boards numbered {2,3,4} or only board {1} or nothing but not boards {2,4,5}.
Example 1:
Input:
n = 5
k = 3
arr[] = {5,10,30,20,15}
Output: 35
Explanation: The most optimal way will be:
Painter 1 allocation : {5,10}
Painter 2 allocation : {30}
Painter 3 allocation : {20,15}
Job will be done when all painters finish
i.e. at time = max(5+10, 30, 20+15) = 35
Example 2:
Input:
n = 4
k = 2
arr[] = {10,20,30,40}
Output: 60
Explanation: The most optimal way to paint:
Painter 1 allocation : {10,20,30}
Painter 2 allocation : {40}
Job will be complete at time = 60
Your task:
Your task is to complete the function minTime() which takes the integers n and k and the array arr[] as input and returns the minimum time required to paint all partitions.
Expected Time Complexity: O(n log m) , m = sum of all boards' length
Expected Auxiliary Space: O(1)
Constraints:
1 β€ n β€ 10^{5}
1 β€ k β€ 10^{5}
1 β€ arr[i] β€ 10^{5} | class Solution:
def minTime(self, arr, n, k):
def numofPainter(maxLen):
painters = 1
total = 0
for board in arr:
total += board
if total > maxLen:
total = board
painters += 1
return painters
low, high = max(arr), sum(arr)
while low < high:
p = low + (high - low) // 2
curr_painters = numofPainter(p)
if curr_painters <= k:
high = p
else:
low = p + 1
return low | CLASS_DEF FUNC_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR VAR ASSIGN VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR |
Dilpreet wants to paint his dog's home that has n boards with different lengths. The length of i^{th }board is given by arr[i] where arr[] is an array of n integers. He hired k painters for this work and each painter takes 1 unit time to paint 1 unit of the board.
The problem is to find the minimum time to get this job done if all painters start together with the constraint that any painter will only paint continuous boards, say boards numbered {2,3,4} or only board {1} or nothing but not boards {2,4,5}.
Example 1:
Input:
n = 5
k = 3
arr[] = {5,10,30,20,15}
Output: 35
Explanation: The most optimal way will be:
Painter 1 allocation : {5,10}
Painter 2 allocation : {30}
Painter 3 allocation : {20,15}
Job will be done when all painters finish
i.e. at time = max(5+10, 30, 20+15) = 35
Example 2:
Input:
n = 4
k = 2
arr[] = {10,20,30,40}
Output: 60
Explanation: The most optimal way to paint:
Painter 1 allocation : {10,20,30}
Painter 2 allocation : {40}
Job will be complete at time = 60
Your task:
Your task is to complete the function minTime() which takes the integers n and k and the array arr[] as input and returns the minimum time required to paint all partitions.
Expected Time Complexity: O(n log m) , m = sum of all boards' length
Expected Auxiliary Space: O(1)
Constraints:
1 β€ n β€ 10^{5}
1 β€ k β€ 10^{5}
1 β€ arr[i] β€ 10^{5} | class Solution:
def minTime(self, arr, n, k):
sum = 0
for i in arr:
sum += i
low = 0
high = sum
mid = (low + high) // 2
ans = -1
while low <= high:
if possible(arr, n, k, mid):
ans = mid
high = mid - 1
else:
low = mid + 1
mid = (low + high) // 2
return ans
def possible(arr, n, k, mid):
c = 1
sum = 0
for i in range(n):
if sum + arr[i] <= mid:
sum = sum + arr[i]
else:
sum = arr[i]
c = c + 1
if c > k or arr[i] > mid:
return False
return True | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER FOR VAR VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER |
Dilpreet wants to paint his dog's home that has n boards with different lengths. The length of i^{th }board is given by arr[i] where arr[] is an array of n integers. He hired k painters for this work and each painter takes 1 unit time to paint 1 unit of the board.
The problem is to find the minimum time to get this job done if all painters start together with the constraint that any painter will only paint continuous boards, say boards numbered {2,3,4} or only board {1} or nothing but not boards {2,4,5}.
Example 1:
Input:
n = 5
k = 3
arr[] = {5,10,30,20,15}
Output: 35
Explanation: The most optimal way will be:
Painter 1 allocation : {5,10}
Painter 2 allocation : {30}
Painter 3 allocation : {20,15}
Job will be done when all painters finish
i.e. at time = max(5+10, 30, 20+15) = 35
Example 2:
Input:
n = 4
k = 2
arr[] = {10,20,30,40}
Output: 60
Explanation: The most optimal way to paint:
Painter 1 allocation : {10,20,30}
Painter 2 allocation : {40}
Job will be complete at time = 60
Your task:
Your task is to complete the function minTime() which takes the integers n and k and the array arr[] as input and returns the minimum time required to paint all partitions.
Expected Time Complexity: O(n log m) , m = sum of all boards' length
Expected Auxiliary Space: O(1)
Constraints:
1 β€ n β€ 10^{5}
1 β€ k β€ 10^{5}
1 β€ arr[i] β€ 10^{5} | class Solution:
def minTime(self, arr, n, k):
s = 0
sumi = 0
ans = -1
for i in arr:
sumi = sumi + i
e = sumi
mid = (s + e) // 2
while s <= e:
if n == 1:
return arr[0]
if self.ispossible(arr, n, k, mid):
ans = mid
e = mid - 1
else:
s = mid + 1
mid = (s + e) // 2
return ans
def ispossible(self, arr, n, k, mid):
sc = 1
ps = 0
for i in range(len(arr)):
if ps + arr[i] <= mid:
ps += arr[i]
else:
sc += 1
if sc > k or arr[i] > mid:
return False
ps = arr[i]
return True | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER WHILE VAR VAR IF VAR NUMBER RETURN VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR RETURN NUMBER |
Dilpreet wants to paint his dog's home that has n boards with different lengths. The length of i^{th }board is given by arr[i] where arr[] is an array of n integers. He hired k painters for this work and each painter takes 1 unit time to paint 1 unit of the board.
The problem is to find the minimum time to get this job done if all painters start together with the constraint that any painter will only paint continuous boards, say boards numbered {2,3,4} or only board {1} or nothing but not boards {2,4,5}.
Example 1:
Input:
n = 5
k = 3
arr[] = {5,10,30,20,15}
Output: 35
Explanation: The most optimal way will be:
Painter 1 allocation : {5,10}
Painter 2 allocation : {30}
Painter 3 allocation : {20,15}
Job will be done when all painters finish
i.e. at time = max(5+10, 30, 20+15) = 35
Example 2:
Input:
n = 4
k = 2
arr[] = {10,20,30,40}
Output: 60
Explanation: The most optimal way to paint:
Painter 1 allocation : {10,20,30}
Painter 2 allocation : {40}
Job will be complete at time = 60
Your task:
Your task is to complete the function minTime() which takes the integers n and k and the array arr[] as input and returns the minimum time required to paint all partitions.
Expected Time Complexity: O(n log m) , m = sum of all boards' length
Expected Auxiliary Space: O(1)
Constraints:
1 β€ n β€ 10^{5}
1 β€ k β€ 10^{5}
1 β€ arr[i] β€ 10^{5} | def isValid(mid, arr, n, k):
sum_ = 0
count = 1
for i in arr:
sum_ += i
if sum_ > mid:
count += 1
sum_ = i
if count > k:
return False
return True
class Solution:
def minTime(self, arr, n, k):
l, r = max(arr), sum(arr)
while l <= r:
mid = l + (r - l) // 2
if isValid(mid, arr, n, k):
r = mid - 1
else:
l = mid + 1
return l | FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER CLASS_DEF FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR |
Dilpreet wants to paint his dog's home that has n boards with different lengths. The length of i^{th }board is given by arr[i] where arr[] is an array of n integers. He hired k painters for this work and each painter takes 1 unit time to paint 1 unit of the board.
The problem is to find the minimum time to get this job done if all painters start together with the constraint that any painter will only paint continuous boards, say boards numbered {2,3,4} or only board {1} or nothing but not boards {2,4,5}.
Example 1:
Input:
n = 5
k = 3
arr[] = {5,10,30,20,15}
Output: 35
Explanation: The most optimal way will be:
Painter 1 allocation : {5,10}
Painter 2 allocation : {30}
Painter 3 allocation : {20,15}
Job will be done when all painters finish
i.e. at time = max(5+10, 30, 20+15) = 35
Example 2:
Input:
n = 4
k = 2
arr[] = {10,20,30,40}
Output: 60
Explanation: The most optimal way to paint:
Painter 1 allocation : {10,20,30}
Painter 2 allocation : {40}
Job will be complete at time = 60
Your task:
Your task is to complete the function minTime() which takes the integers n and k and the array arr[] as input and returns the minimum time required to paint all partitions.
Expected Time Complexity: O(n log m) , m = sum of all boards' length
Expected Auxiliary Space: O(1)
Constraints:
1 β€ n β€ 10^{5}
1 β€ k β€ 10^{5}
1 β€ arr[i] β€ 10^{5} | class Solution:
def minTime(self, arr, n, k):
l = 0
r = 0
for i in range(len(arr)):
r = r + arr[i]
mid = l + (r - l) // 2
ans = -1
def ispossible(mid, arr, k):
pc = 1
cs = 0
for i in range(len(arr)):
if cs + arr[i] <= mid:
cs = cs + arr[i]
else:
pc = pc + 1
if pc > k or arr[i] > mid:
return False
cs = arr[i]
return True
while l <= r:
mid = l + (r - l) // 2
if ispossible(mid, arr, k):
ans = mid
r = mid - 1
else:
l = mid + 1
return ans | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR RETURN NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR |
Dilpreet wants to paint his dog's home that has n boards with different lengths. The length of i^{th }board is given by arr[i] where arr[] is an array of n integers. He hired k painters for this work and each painter takes 1 unit time to paint 1 unit of the board.
The problem is to find the minimum time to get this job done if all painters start together with the constraint that any painter will only paint continuous boards, say boards numbered {2,3,4} or only board {1} or nothing but not boards {2,4,5}.
Example 1:
Input:
n = 5
k = 3
arr[] = {5,10,30,20,15}
Output: 35
Explanation: The most optimal way will be:
Painter 1 allocation : {5,10}
Painter 2 allocation : {30}
Painter 3 allocation : {20,15}
Job will be done when all painters finish
i.e. at time = max(5+10, 30, 20+15) = 35
Example 2:
Input:
n = 4
k = 2
arr[] = {10,20,30,40}
Output: 60
Explanation: The most optimal way to paint:
Painter 1 allocation : {10,20,30}
Painter 2 allocation : {40}
Job will be complete at time = 60
Your task:
Your task is to complete the function minTime() which takes the integers n and k and the array arr[] as input and returns the minimum time required to paint all partitions.
Expected Time Complexity: O(n log m) , m = sum of all boards' length
Expected Auxiliary Space: O(1)
Constraints:
1 β€ n β€ 10^{5}
1 β€ k β€ 10^{5}
1 β€ arr[i] β€ 10^{5} | class Solution:
def ifpossible(self, arr, n, k, mid):
load = 0
painter = 1
for board in arr:
load += board
if load > mid:
painter += 1
load = board
return painter <= k
def recursion(self, arr, n, k, start, end, ans):
if start > end:
return ans
mid = (start + end) // 2
output = self.ifpossible(arr, n, k, mid)
if output:
ans = mid
end = mid - 1
return self.recursion(arr, n, k, start, end, ans)
else:
start = mid + 1
return self.recursion(arr, n, k, start, end, ans)
def minTime(self, arr, n, k):
start, end = max(arr), sum(arr)
ans = -1
return self.recursion(arr, n, k, start, end, ans) | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR RETURN VAR VAR FUNC_DEF IF VAR VAR RETURN VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR VAR IF VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR VAR VAR VAR FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER RETURN FUNC_CALL VAR VAR VAR VAR VAR VAR VAR |
Dilpreet wants to paint his dog's home that has n boards with different lengths. The length of i^{th }board is given by arr[i] where arr[] is an array of n integers. He hired k painters for this work and each painter takes 1 unit time to paint 1 unit of the board.
The problem is to find the minimum time to get this job done if all painters start together with the constraint that any painter will only paint continuous boards, say boards numbered {2,3,4} or only board {1} or nothing but not boards {2,4,5}.
Example 1:
Input:
n = 5
k = 3
arr[] = {5,10,30,20,15}
Output: 35
Explanation: The most optimal way will be:
Painter 1 allocation : {5,10}
Painter 2 allocation : {30}
Painter 3 allocation : {20,15}
Job will be done when all painters finish
i.e. at time = max(5+10, 30, 20+15) = 35
Example 2:
Input:
n = 4
k = 2
arr[] = {10,20,30,40}
Output: 60
Explanation: The most optimal way to paint:
Painter 1 allocation : {10,20,30}
Painter 2 allocation : {40}
Job will be complete at time = 60
Your task:
Your task is to complete the function minTime() which takes the integers n and k and the array arr[] as input and returns the minimum time required to paint all partitions.
Expected Time Complexity: O(n log m) , m = sum of all boards' length
Expected Auxiliary Space: O(1)
Constraints:
1 β€ n β€ 10^{5}
1 β€ k β€ 10^{5}
1 β€ arr[i] β€ 10^{5} | class Solution:
def isPossible(arr, n, k, mid):
time_sum = 0
painter_count = 1
for i in range(n):
if time_sum + arr[i] <= mid:
time_sum += arr[i]
else:
painter_count += 1
if painter_count > k or arr[i] > mid:
return False
time_sum = arr[i]
return True
def minTime(self, arr, n, k):
low = 0
high = sum(arr)
mid = int(low + (high - low) / 2)
ans = -1
while low <= high:
if Solution.isPossible(arr, n, k, mid):
ans = mid
high = mid - 1
else:
low = mid + 1
mid = int(low + (high - low) / 2)
return ans | CLASS_DEF FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR RETURN NUMBER ASSIGN VAR VAR VAR RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN VAR |
Consider a sequence of integers $a_1, a_2, \ldots, a_n$. In one move, you can select any element of the sequence and delete it. After an element is deleted, all elements to the right are shifted to the left by $1$ position, so there are no empty spaces in the sequence. So after you make a move, the sequence's length decreases by $1$. The indices of the elements after the move are recalculated.
E. g. let the sequence be $a=[3, 2, 2, 1, 5]$. Let's select the element $a_3=2$ in a move. Then after the move the sequence will be equal to $a=[3, 2, 1, 5]$, so the $3$-rd element of the new sequence will be $a_3=1$ and the $4$-th element will be $a_4=5$.
You are given a sequence $a_1, a_2, \ldots, a_n$ and a number $k$. You need to find the minimum number of moves you have to make so that in the resulting sequence there will be at least $k$ elements that are equal to their indices, i. e. the resulting sequence $b_1, b_2, \ldots, b_m$ will contain at least $k$ indices $i$ such that $b_i = i$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases. Then $t$ test cases follow.
Each test case consists of two consecutive lines. The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 2000$). The second line contains a sequence of integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$). The numbers in the sequence are not necessarily different.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $2000$.
-----Output-----
For each test case output in a single line:
$-1$ if there's no desired move sequence;
otherwise, the integer $x$ ($0 \le x \le n$) β the minimum number of the moves to be made so that the resulting sequence will contain at least $k$ elements that are equal to their indices.
-----Examples-----
Input
4
7 6
1 1 2 3 4 5 6
5 2
5 1 3 2 3
5 2
5 5 5 5 4
8 4
1 2 3 3 2 2 5 5
Output
1
2
-1
2
-----Note-----
In the first test case the sequence doesn't satisfy the desired condition, but it can be provided by deleting the first element, hence the sequence will be $[1, 2, 3, 4, 5, 6]$ and $6$ elements will be equal to their indices.
In the second test case there are two ways to get the desired result in $2$ moves: the first one is to delete the $1$-st and the $3$-rd elements so that the sequence will be $[1, 2, 3]$ and have $3$ elements equal to their indices; the second way is to delete the $2$-nd and the $3$-rd elements to get the sequence $[5, 2, 3]$ with $2$ desired elements. | t = int(input())
for _ in range(t):
n, k = map(int, input().split())
nums = list(map(int, input().split()))
dp = [[(0) for j in range(n + 1)] for i in range(n + 1)]
ans = n + 1
for i in range(n):
for j in range(i + 2):
dp[i + 1][j] = dp[i][j - 1]
if nums[i] == i - j + 1:
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j] + 1)
else:
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
if dp[i + 1][j] >= k:
ans = min(ans, j)
break
if ans == n + 1:
print(-1)
else:
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR 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 NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR IF VAR BIN_OP VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR |
Consider a sequence of integers $a_1, a_2, \ldots, a_n$. In one move, you can select any element of the sequence and delete it. After an element is deleted, all elements to the right are shifted to the left by $1$ position, so there are no empty spaces in the sequence. So after you make a move, the sequence's length decreases by $1$. The indices of the elements after the move are recalculated.
E. g. let the sequence be $a=[3, 2, 2, 1, 5]$. Let's select the element $a_3=2$ in a move. Then after the move the sequence will be equal to $a=[3, 2, 1, 5]$, so the $3$-rd element of the new sequence will be $a_3=1$ and the $4$-th element will be $a_4=5$.
You are given a sequence $a_1, a_2, \ldots, a_n$ and a number $k$. You need to find the minimum number of moves you have to make so that in the resulting sequence there will be at least $k$ elements that are equal to their indices, i. e. the resulting sequence $b_1, b_2, \ldots, b_m$ will contain at least $k$ indices $i$ such that $b_i = i$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases. Then $t$ test cases follow.
Each test case consists of two consecutive lines. The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 2000$). The second line contains a sequence of integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$). The numbers in the sequence are not necessarily different.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $2000$.
-----Output-----
For each test case output in a single line:
$-1$ if there's no desired move sequence;
otherwise, the integer $x$ ($0 \le x \le n$) β the minimum number of the moves to be made so that the resulting sequence will contain at least $k$ elements that are equal to their indices.
-----Examples-----
Input
4
7 6
1 1 2 3 4 5 6
5 2
5 1 3 2 3
5 2
5 5 5 5 4
8 4
1 2 3 3 2 2 5 5
Output
1
2
-1
2
-----Note-----
In the first test case the sequence doesn't satisfy the desired condition, but it can be provided by deleting the first element, hence the sequence will be $[1, 2, 3, 4, 5, 6]$ and $6$ elements will be equal to their indices.
In the second test case there are two ways to get the desired result in $2$ moves: the first one is to delete the $1$-st and the $3$-rd elements so that the sequence will be $[1, 2, 3]$ and have $3$ elements equal to their indices; the second way is to delete the $2$-nd and the $3$-rd elements to get the sequence $[5, 2, 3]$ with $2$ desired elements. | import sys
from sys import stdin
tt = int(stdin.readline())
for loop in range(tt):
n, k = map(int, stdin.readline().split())
a = list(map(int, stdin.readline().split()))
dp = [([float("-inf")] * (n + 1)) for i in range(n + 1)]
dp[0][0] = 0
for i in range(n + 1):
for j in range(n + 1):
if j != 0:
dp[i][j] = max(dp[i][j], dp[i][j - 1])
if i != 0 and j != 0:
if a[j - 1] == i:
dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1)
else:
dp[i][j] = max(dp[i][j], dp[i - 1][j - 1])
ans = float("inf")
for i in range(n + 1):
for j in range(n + 1):
if dp[i][j] >= k:
ans = min(ans, j - i)
print(ans if ans != float("inf") else -1) | IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR 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 BIN_OP LIST FUNC_CALL VAR STRING BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR NUMBER |
Consider a sequence of integers $a_1, a_2, \ldots, a_n$. In one move, you can select any element of the sequence and delete it. After an element is deleted, all elements to the right are shifted to the left by $1$ position, so there are no empty spaces in the sequence. So after you make a move, the sequence's length decreases by $1$. The indices of the elements after the move are recalculated.
E. g. let the sequence be $a=[3, 2, 2, 1, 5]$. Let's select the element $a_3=2$ in a move. Then after the move the sequence will be equal to $a=[3, 2, 1, 5]$, so the $3$-rd element of the new sequence will be $a_3=1$ and the $4$-th element will be $a_4=5$.
You are given a sequence $a_1, a_2, \ldots, a_n$ and a number $k$. You need to find the minimum number of moves you have to make so that in the resulting sequence there will be at least $k$ elements that are equal to their indices, i. e. the resulting sequence $b_1, b_2, \ldots, b_m$ will contain at least $k$ indices $i$ such that $b_i = i$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases. Then $t$ test cases follow.
Each test case consists of two consecutive lines. The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 2000$). The second line contains a sequence of integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$). The numbers in the sequence are not necessarily different.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $2000$.
-----Output-----
For each test case output in a single line:
$-1$ if there's no desired move sequence;
otherwise, the integer $x$ ($0 \le x \le n$) β the minimum number of the moves to be made so that the resulting sequence will contain at least $k$ elements that are equal to their indices.
-----Examples-----
Input
4
7 6
1 1 2 3 4 5 6
5 2
5 1 3 2 3
5 2
5 5 5 5 4
8 4
1 2 3 3 2 2 5 5
Output
1
2
-1
2
-----Note-----
In the first test case the sequence doesn't satisfy the desired condition, but it can be provided by deleting the first element, hence the sequence will be $[1, 2, 3, 4, 5, 6]$ and $6$ elements will be equal to their indices.
In the second test case there are two ways to get the desired result in $2$ moves: the first one is to delete the $1$-st and the $3$-rd elements so that the sequence will be $[1, 2, 3]$ and have $3$ elements equal to their indices; the second way is to delete the $2$-nd and the $3$-rd elements to get the sequence $[5, 2, 3]$ with $2$ desired elements. | for _ in range(int(input())):
n, k = map(int, input().split())
d = [0] + list(map(int, input().split()))
dp = [-1] * (n + 1)
dp[0] = 0
for i in range(1, n + 1):
for j in range(i, 0, -1):
dp[j] = max(dp[j], dp[j - 1] + (1 if d[i] == j else 0))
for i in range(n, 0, -1):
if dp[i] >= k:
print(n - i)
break
else:
print(-1) | FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR NUMBER |
Consider a sequence of integers $a_1, a_2, \ldots, a_n$. In one move, you can select any element of the sequence and delete it. After an element is deleted, all elements to the right are shifted to the left by $1$ position, so there are no empty spaces in the sequence. So after you make a move, the sequence's length decreases by $1$. The indices of the elements after the move are recalculated.
E. g. let the sequence be $a=[3, 2, 2, 1, 5]$. Let's select the element $a_3=2$ in a move. Then after the move the sequence will be equal to $a=[3, 2, 1, 5]$, so the $3$-rd element of the new sequence will be $a_3=1$ and the $4$-th element will be $a_4=5$.
You are given a sequence $a_1, a_2, \ldots, a_n$ and a number $k$. You need to find the minimum number of moves you have to make so that in the resulting sequence there will be at least $k$ elements that are equal to their indices, i. e. the resulting sequence $b_1, b_2, \ldots, b_m$ will contain at least $k$ indices $i$ such that $b_i = i$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases. Then $t$ test cases follow.
Each test case consists of two consecutive lines. The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 2000$). The second line contains a sequence of integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$). The numbers in the sequence are not necessarily different.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $2000$.
-----Output-----
For each test case output in a single line:
$-1$ if there's no desired move sequence;
otherwise, the integer $x$ ($0 \le x \le n$) β the minimum number of the moves to be made so that the resulting sequence will contain at least $k$ elements that are equal to their indices.
-----Examples-----
Input
4
7 6
1 1 2 3 4 5 6
5 2
5 1 3 2 3
5 2
5 5 5 5 4
8 4
1 2 3 3 2 2 5 5
Output
1
2
-1
2
-----Note-----
In the first test case the sequence doesn't satisfy the desired condition, but it can be provided by deleting the first element, hence the sequence will be $[1, 2, 3, 4, 5, 6]$ and $6$ elements will be equal to their indices.
In the second test case there are two ways to get the desired result in $2$ moves: the first one is to delete the $1$-st and the $3$-rd elements so that the sequence will be $[1, 2, 3]$ and have $3$ elements equal to their indices; the second way is to delete the $2$-nd and the $3$-rd elements to get the sequence $[5, 2, 3]$ with $2$ desired elements. | import sys
input = sys.stdin.readline
def main():
n, k = map(int, input().split())
alst = list(map(int, input().split()))
inf = -(10**8)
dp = [([inf] * (n + 1)) for _ in range(n + 1)]
dp[0][0] = 0
for i, a in enumerate(alst, 1):
for j in range(n + 1):
dp[i][j] = dp[i - 1][j]
if j != 0:
dp[i][j] = max(dp[i][j], dp[i - 1][j - 1])
if a == j:
dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1)
for i in range(n, k - 1, -1):
if dp[-1][i] >= k:
print(n - i)
return
print(-1)
for _ in range(int(input())):
main() | IMPORT ASSIGN VAR VAR FUNC_DEF 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 BIN_OP NUMBER NUMBER ASSIGN VAR BIN_OP LIST VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR VAR FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER NUMBER IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR RETURN EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR |
Consider a sequence of integers $a_1, a_2, \ldots, a_n$. In one move, you can select any element of the sequence and delete it. After an element is deleted, all elements to the right are shifted to the left by $1$ position, so there are no empty spaces in the sequence. So after you make a move, the sequence's length decreases by $1$. The indices of the elements after the move are recalculated.
E. g. let the sequence be $a=[3, 2, 2, 1, 5]$. Let's select the element $a_3=2$ in a move. Then after the move the sequence will be equal to $a=[3, 2, 1, 5]$, so the $3$-rd element of the new sequence will be $a_3=1$ and the $4$-th element will be $a_4=5$.
You are given a sequence $a_1, a_2, \ldots, a_n$ and a number $k$. You need to find the minimum number of moves you have to make so that in the resulting sequence there will be at least $k$ elements that are equal to their indices, i. e. the resulting sequence $b_1, b_2, \ldots, b_m$ will contain at least $k$ indices $i$ such that $b_i = i$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases. Then $t$ test cases follow.
Each test case consists of two consecutive lines. The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 2000$). The second line contains a sequence of integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$). The numbers in the sequence are not necessarily different.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $2000$.
-----Output-----
For each test case output in a single line:
$-1$ if there's no desired move sequence;
otherwise, the integer $x$ ($0 \le x \le n$) β the minimum number of the moves to be made so that the resulting sequence will contain at least $k$ elements that are equal to their indices.
-----Examples-----
Input
4
7 6
1 1 2 3 4 5 6
5 2
5 1 3 2 3
5 2
5 5 5 5 4
8 4
1 2 3 3 2 2 5 5
Output
1
2
-1
2
-----Note-----
In the first test case the sequence doesn't satisfy the desired condition, but it can be provided by deleting the first element, hence the sequence will be $[1, 2, 3, 4, 5, 6]$ and $6$ elements will be equal to their indices.
In the second test case there are two ways to get the desired result in $2$ moves: the first one is to delete the $1$-st and the $3$-rd elements so that the sequence will be $[1, 2, 3]$ and have $3$ elements equal to their indices; the second way is to delete the $2$-nd and the $3$-rd elements to get the sequence $[5, 2, 3]$ with $2$ desired elements. | def solve(A, k):
n = len(A)
dp = [([0] * (n + 1)) for _ in range(n + 1)]
for i in range(n):
for l in range(1, i + 2):
dp[i][l] = max(dp[i][l], dp[i - 1][l])
d = 1 if A[i] == l else 0
dp[i][l] = max(dp[i][l], dp[i - 1][l - 1] + d)
for i in reversed(range(n + 1)):
if dp[n - 1][i] >= k:
return n - i
return -1
T = int(input())
for _ in range(T):
n, k = map(int, input().split(" "))
A = list(map(int, input().split(" ")))
print(solve(A, k)) | FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR RETURN BIN_OP VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN 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 EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR |
Consider a sequence of integers $a_1, a_2, \ldots, a_n$. In one move, you can select any element of the sequence and delete it. After an element is deleted, all elements to the right are shifted to the left by $1$ position, so there are no empty spaces in the sequence. So after you make a move, the sequence's length decreases by $1$. The indices of the elements after the move are recalculated.
E. g. let the sequence be $a=[3, 2, 2, 1, 5]$. Let's select the element $a_3=2$ in a move. Then after the move the sequence will be equal to $a=[3, 2, 1, 5]$, so the $3$-rd element of the new sequence will be $a_3=1$ and the $4$-th element will be $a_4=5$.
You are given a sequence $a_1, a_2, \ldots, a_n$ and a number $k$. You need to find the minimum number of moves you have to make so that in the resulting sequence there will be at least $k$ elements that are equal to their indices, i. e. the resulting sequence $b_1, b_2, \ldots, b_m$ will contain at least $k$ indices $i$ such that $b_i = i$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases. Then $t$ test cases follow.
Each test case consists of two consecutive lines. The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 2000$). The second line contains a sequence of integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$). The numbers in the sequence are not necessarily different.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $2000$.
-----Output-----
For each test case output in a single line:
$-1$ if there's no desired move sequence;
otherwise, the integer $x$ ($0 \le x \le n$) β the minimum number of the moves to be made so that the resulting sequence will contain at least $k$ elements that are equal to their indices.
-----Examples-----
Input
4
7 6
1 1 2 3 4 5 6
5 2
5 1 3 2 3
5 2
5 5 5 5 4
8 4
1 2 3 3 2 2 5 5
Output
1
2
-1
2
-----Note-----
In the first test case the sequence doesn't satisfy the desired condition, but it can be provided by deleting the first element, hence the sequence will be $[1, 2, 3, 4, 5, 6]$ and $6$ elements will be equal to their indices.
In the second test case there are two ways to get the desired result in $2$ moves: the first one is to delete the $1$-st and the $3$-rd elements so that the sequence will be $[1, 2, 3]$ and have $3$ elements equal to their indices; the second way is to delete the $2$-nd and the $3$-rd elements to get the sequence $[5, 2, 3]$ with $2$ desired elements. | t = int(input())
for _ in range(t):
n, k = map(int, input().split())
a = list(map(int, input().split()))
DP = [[(0) for i in range(n + 1)] for j in range(n + 1)]
for m in range(1, n + 1):
for d in range(0, m + 1):
if m - a[m - 1] == d:
if d == 0:
DP[m][0] = DP[m - 1][0] + 1
else:
DP[m][d] = max(DP[m - 1][d] + 1, DP[m - 1][d - 1])
elif d == 0:
DP[m][0] = DP[m - 1][0]
else:
DP[m][d] = max(DP[m - 1][d], DP[m - 1][d - 1])
operations = None
for d in range(n + 1):
if DP[n][d] >= k:
operations = d
break
if operations != None:
print(operations)
else:
print(-1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR 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 NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF BIN_OP VAR VAR BIN_OP VAR NUMBER VAR IF VAR NUMBER ASSIGN VAR VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NONE FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR VAR IF VAR NONE EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER |
Consider a sequence of integers $a_1, a_2, \ldots, a_n$. In one move, you can select any element of the sequence and delete it. After an element is deleted, all elements to the right are shifted to the left by $1$ position, so there are no empty spaces in the sequence. So after you make a move, the sequence's length decreases by $1$. The indices of the elements after the move are recalculated.
E. g. let the sequence be $a=[3, 2, 2, 1, 5]$. Let's select the element $a_3=2$ in a move. Then after the move the sequence will be equal to $a=[3, 2, 1, 5]$, so the $3$-rd element of the new sequence will be $a_3=1$ and the $4$-th element will be $a_4=5$.
You are given a sequence $a_1, a_2, \ldots, a_n$ and a number $k$. You need to find the minimum number of moves you have to make so that in the resulting sequence there will be at least $k$ elements that are equal to their indices, i. e. the resulting sequence $b_1, b_2, \ldots, b_m$ will contain at least $k$ indices $i$ such that $b_i = i$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases. Then $t$ test cases follow.
Each test case consists of two consecutive lines. The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 2000$). The second line contains a sequence of integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$). The numbers in the sequence are not necessarily different.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $2000$.
-----Output-----
For each test case output in a single line:
$-1$ if there's no desired move sequence;
otherwise, the integer $x$ ($0 \le x \le n$) β the minimum number of the moves to be made so that the resulting sequence will contain at least $k$ elements that are equal to their indices.
-----Examples-----
Input
4
7 6
1 1 2 3 4 5 6
5 2
5 1 3 2 3
5 2
5 5 5 5 4
8 4
1 2 3 3 2 2 5 5
Output
1
2
-1
2
-----Note-----
In the first test case the sequence doesn't satisfy the desired condition, but it can be provided by deleting the first element, hence the sequence will be $[1, 2, 3, 4, 5, 6]$ and $6$ elements will be equal to their indices.
In the second test case there are two ways to get the desired result in $2$ moves: the first one is to delete the $1$-st and the $3$-rd elements so that the sequence will be $[1, 2, 3]$ and have $3$ elements equal to their indices; the second way is to delete the $2$-nd and the $3$-rd elements to get the sequence $[5, 2, 3]$ with $2$ desired elements. | import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
dp = [(0) for i in range(n + 1)]
inf = float("inf")
an = inf
for i in range(1, n + 1):
b = -1
for j in range(0, i):
if a[i] > a[j] and a[i] - a[j] <= i - j:
b = max(b, dp[j] + 1)
dp[i] = b
if b >= k:
an = min(an, i - a[i])
if an == inf:
print(-1)
else:
print(an) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR |
Consider a sequence of integers $a_1, a_2, \ldots, a_n$. In one move, you can select any element of the sequence and delete it. After an element is deleted, all elements to the right are shifted to the left by $1$ position, so there are no empty spaces in the sequence. So after you make a move, the sequence's length decreases by $1$. The indices of the elements after the move are recalculated.
E. g. let the sequence be $a=[3, 2, 2, 1, 5]$. Let's select the element $a_3=2$ in a move. Then after the move the sequence will be equal to $a=[3, 2, 1, 5]$, so the $3$-rd element of the new sequence will be $a_3=1$ and the $4$-th element will be $a_4=5$.
You are given a sequence $a_1, a_2, \ldots, a_n$ and a number $k$. You need to find the minimum number of moves you have to make so that in the resulting sequence there will be at least $k$ elements that are equal to their indices, i. e. the resulting sequence $b_1, b_2, \ldots, b_m$ will contain at least $k$ indices $i$ such that $b_i = i$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases. Then $t$ test cases follow.
Each test case consists of two consecutive lines. The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 2000$). The second line contains a sequence of integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$). The numbers in the sequence are not necessarily different.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $2000$.
-----Output-----
For each test case output in a single line:
$-1$ if there's no desired move sequence;
otherwise, the integer $x$ ($0 \le x \le n$) β the minimum number of the moves to be made so that the resulting sequence will contain at least $k$ elements that are equal to their indices.
-----Examples-----
Input
4
7 6
1 1 2 3 4 5 6
5 2
5 1 3 2 3
5 2
5 5 5 5 4
8 4
1 2 3 3 2 2 5 5
Output
1
2
-1
2
-----Note-----
In the first test case the sequence doesn't satisfy the desired condition, but it can be provided by deleting the first element, hence the sequence will be $[1, 2, 3, 4, 5, 6]$ and $6$ elements will be equal to their indices.
In the second test case there are two ways to get the desired result in $2$ moves: the first one is to delete the $1$-st and the $3$-rd elements so that the sequence will be $[1, 2, 3]$ and have $3$ elements equal to their indices; the second way is to delete the $2$-nd and the $3$-rd elements to get the sequence $[5, 2, 3]$ with $2$ desired elements. | import sys
input = sys.stdin.readline
for _ in range(int(input())):
n, k = map(int, input().split())
A = list(map(int, input().split()))
dp = [([0] * (n + 1)) for _ in range(n + 1)]
ans = float("inf")
for i in range(1, n + 1):
for j in range(i + 1):
if j == 0:
dp[i][j] = dp[i - 1][j] + (A[i - 1] == i)
else:
dp[i][j] = max(dp[i - 1][j] + (A[i - 1] == i - j), dp[i - 1][j - 1])
if dp[i][j] >= k:
ans = min(ans, j)
print(ans if ans < float("inf") else -1) | IMPORT ASSIGN VAR VAR FOR VAR FUNC_CALL 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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR FUNC_CALL VAR STRING VAR NUMBER |
Consider a sequence of integers $a_1, a_2, \ldots, a_n$. In one move, you can select any element of the sequence and delete it. After an element is deleted, all elements to the right are shifted to the left by $1$ position, so there are no empty spaces in the sequence. So after you make a move, the sequence's length decreases by $1$. The indices of the elements after the move are recalculated.
E. g. let the sequence be $a=[3, 2, 2, 1, 5]$. Let's select the element $a_3=2$ in a move. Then after the move the sequence will be equal to $a=[3, 2, 1, 5]$, so the $3$-rd element of the new sequence will be $a_3=1$ and the $4$-th element will be $a_4=5$.
You are given a sequence $a_1, a_2, \ldots, a_n$ and a number $k$. You need to find the minimum number of moves you have to make so that in the resulting sequence there will be at least $k$ elements that are equal to their indices, i. e. the resulting sequence $b_1, b_2, \ldots, b_m$ will contain at least $k$ indices $i$ such that $b_i = i$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases. Then $t$ test cases follow.
Each test case consists of two consecutive lines. The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 2000$). The second line contains a sequence of integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$). The numbers in the sequence are not necessarily different.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $2000$.
-----Output-----
For each test case output in a single line:
$-1$ if there's no desired move sequence;
otherwise, the integer $x$ ($0 \le x \le n$) β the minimum number of the moves to be made so that the resulting sequence will contain at least $k$ elements that are equal to their indices.
-----Examples-----
Input
4
7 6
1 1 2 3 4 5 6
5 2
5 1 3 2 3
5 2
5 5 5 5 4
8 4
1 2 3 3 2 2 5 5
Output
1
2
-1
2
-----Note-----
In the first test case the sequence doesn't satisfy the desired condition, but it can be provided by deleting the first element, hence the sequence will be $[1, 2, 3, 4, 5, 6]$ and $6$ elements will be equal to their indices.
In the second test case there are two ways to get the desired result in $2$ moves: the first one is to delete the $1$-st and the $3$-rd elements so that the sequence will be $[1, 2, 3]$ and have $3$ elements equal to their indices; the second way is to delete the $2$-nd and the $3$-rd elements to get the sequence $[5, 2, 3]$ with $2$ desired elements. | t = int(input())
while t:
t -= 1
n, k = [int(c) for c in input().split()]
arr = [0] + [int(c) for c in input().split()]
dp = [[(0) for x in range(n + 1)] for xi in range(n + 1)]
for i in range(1, n + 1):
for j in range(i + 1):
dp[i][j] = max(dp[i][j], dp[i - 1][j - 1])
if arr[i] == i - j:
if i - 1 >= j:
dp[i][j] = max(dp[i][j], dp[i - 1][j] + 1)
elif i - 1 >= j:
dp[i][j] = max(dp[i - 1][j], dp[i][j])
for i in range(n + 1):
if dp[-1][i] >= k:
print(i)
break
else:
print(-1) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR BIN_OP VAR VAR IF BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER |
Consider a sequence of integers $a_1, a_2, \ldots, a_n$. In one move, you can select any element of the sequence and delete it. After an element is deleted, all elements to the right are shifted to the left by $1$ position, so there are no empty spaces in the sequence. So after you make a move, the sequence's length decreases by $1$. The indices of the elements after the move are recalculated.
E. g. let the sequence be $a=[3, 2, 2, 1, 5]$. Let's select the element $a_3=2$ in a move. Then after the move the sequence will be equal to $a=[3, 2, 1, 5]$, so the $3$-rd element of the new sequence will be $a_3=1$ and the $4$-th element will be $a_4=5$.
You are given a sequence $a_1, a_2, \ldots, a_n$ and a number $k$. You need to find the minimum number of moves you have to make so that in the resulting sequence there will be at least $k$ elements that are equal to their indices, i. e. the resulting sequence $b_1, b_2, \ldots, b_m$ will contain at least $k$ indices $i$ such that $b_i = i$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases. Then $t$ test cases follow.
Each test case consists of two consecutive lines. The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 2000$). The second line contains a sequence of integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$). The numbers in the sequence are not necessarily different.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $2000$.
-----Output-----
For each test case output in a single line:
$-1$ if there's no desired move sequence;
otherwise, the integer $x$ ($0 \le x \le n$) β the minimum number of the moves to be made so that the resulting sequence will contain at least $k$ elements that are equal to their indices.
-----Examples-----
Input
4
7 6
1 1 2 3 4 5 6
5 2
5 1 3 2 3
5 2
5 5 5 5 4
8 4
1 2 3 3 2 2 5 5
Output
1
2
-1
2
-----Note-----
In the first test case the sequence doesn't satisfy the desired condition, but it can be provided by deleting the first element, hence the sequence will be $[1, 2, 3, 4, 5, 6]$ and $6$ elements will be equal to their indices.
In the second test case there are two ways to get the desired result in $2$ moves: the first one is to delete the $1$-st and the $3$-rd elements so that the sequence will be $[1, 2, 3]$ and have $3$ elements equal to their indices; the second way is to delete the $2$-nd and the $3$-rd elements to get the sequence $[5, 2, 3]$ with $2$ desired elements. | t = int(input())
def solve(a, n, k):
inf = n + 2
b = [(i - x if i - x >= 0 else inf) for i, x in enumerate(a)]
dp = [1]
for i in range(1, n):
result = 0
for j in range(i):
if b[j] <= b[i] and i - j > b[i] - b[j]:
result = max(result, dp[j])
dp.append(result + 1)
m = inf
for i in range(n):
if dp[i] >= k:
m = min(m, b[i])
return m if m < inf else -1
for test in range(t):
n, k = [int(x) for x in input().split()]
a = [(int(x) - 1) for x in input().split()]
print(solve(a, n, k)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER BIN_OP VAR VAR VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR RETURN VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR |
Consider a sequence of integers $a_1, a_2, \ldots, a_n$. In one move, you can select any element of the sequence and delete it. After an element is deleted, all elements to the right are shifted to the left by $1$ position, so there are no empty spaces in the sequence. So after you make a move, the sequence's length decreases by $1$. The indices of the elements after the move are recalculated.
E. g. let the sequence be $a=[3, 2, 2, 1, 5]$. Let's select the element $a_3=2$ in a move. Then after the move the sequence will be equal to $a=[3, 2, 1, 5]$, so the $3$-rd element of the new sequence will be $a_3=1$ and the $4$-th element will be $a_4=5$.
You are given a sequence $a_1, a_2, \ldots, a_n$ and a number $k$. You need to find the minimum number of moves you have to make so that in the resulting sequence there will be at least $k$ elements that are equal to their indices, i. e. the resulting sequence $b_1, b_2, \ldots, b_m$ will contain at least $k$ indices $i$ such that $b_i = i$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases. Then $t$ test cases follow.
Each test case consists of two consecutive lines. The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 2000$). The second line contains a sequence of integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$). The numbers in the sequence are not necessarily different.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $2000$.
-----Output-----
For each test case output in a single line:
$-1$ if there's no desired move sequence;
otherwise, the integer $x$ ($0 \le x \le n$) β the minimum number of the moves to be made so that the resulting sequence will contain at least $k$ elements that are equal to their indices.
-----Examples-----
Input
4
7 6
1 1 2 3 4 5 6
5 2
5 1 3 2 3
5 2
5 5 5 5 4
8 4
1 2 3 3 2 2 5 5
Output
1
2
-1
2
-----Note-----
In the first test case the sequence doesn't satisfy the desired condition, but it can be provided by deleting the first element, hence the sequence will be $[1, 2, 3, 4, 5, 6]$ and $6$ elements will be equal to their indices.
In the second test case there are two ways to get the desired result in $2$ moves: the first one is to delete the $1$-st and the $3$-rd elements so that the sequence will be $[1, 2, 3]$ and have $3$ elements equal to their indices; the second way is to delete the $2$-nd and the $3$-rd elements to get the sequence $[5, 2, 3]$ with $2$ desired elements. | def printResult():
for i in range(n, 0, -1):
if f[n][i] >= k:
print(n - i)
return
print(-1)
test = int(input())
for _ in range(test):
n, k = map(int, input().split())
a = list(map(int, input().split()))
a = [0] + a
f = [[(0) for _ in range(n + 1)] for _ in range(n + 1)]
for i in range(1, n + 1):
for j in range(1, i + 1):
f[i][j] = f[i - 1][j]
if a[i] == j:
f[i][j] = max(f[i][j], f[i - 1][j - 1] + 1)
else:
f[i][j] = max(f[i][j], f[i - 1][j - 1])
printResult() | FUNC_DEF FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR RETURN EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR 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 BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER EXPR FUNC_CALL VAR |
Consider a sequence of integers $a_1, a_2, \ldots, a_n$. In one move, you can select any element of the sequence and delete it. After an element is deleted, all elements to the right are shifted to the left by $1$ position, so there are no empty spaces in the sequence. So after you make a move, the sequence's length decreases by $1$. The indices of the elements after the move are recalculated.
E. g. let the sequence be $a=[3, 2, 2, 1, 5]$. Let's select the element $a_3=2$ in a move. Then after the move the sequence will be equal to $a=[3, 2, 1, 5]$, so the $3$-rd element of the new sequence will be $a_3=1$ and the $4$-th element will be $a_4=5$.
You are given a sequence $a_1, a_2, \ldots, a_n$ and a number $k$. You need to find the minimum number of moves you have to make so that in the resulting sequence there will be at least $k$ elements that are equal to their indices, i. e. the resulting sequence $b_1, b_2, \ldots, b_m$ will contain at least $k$ indices $i$ such that $b_i = i$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases. Then $t$ test cases follow.
Each test case consists of two consecutive lines. The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 2000$). The second line contains a sequence of integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$). The numbers in the sequence are not necessarily different.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $2000$.
-----Output-----
For each test case output in a single line:
$-1$ if there's no desired move sequence;
otherwise, the integer $x$ ($0 \le x \le n$) β the minimum number of the moves to be made so that the resulting sequence will contain at least $k$ elements that are equal to their indices.
-----Examples-----
Input
4
7 6
1 1 2 3 4 5 6
5 2
5 1 3 2 3
5 2
5 5 5 5 4
8 4
1 2 3 3 2 2 5 5
Output
1
2
-1
2
-----Note-----
In the first test case the sequence doesn't satisfy the desired condition, but it can be provided by deleting the first element, hence the sequence will be $[1, 2, 3, 4, 5, 6]$ and $6$ elements will be equal to their indices.
In the second test case there are two ways to get the desired result in $2$ moves: the first one is to delete the $1$-st and the $3$-rd elements so that the sequence will be $[1, 2, 3]$ and have $3$ elements equal to their indices; the second way is to delete the $2$-nd and the $3$-rd elements to get the sequence $[5, 2, 3]$ with $2$ desired elements. | import sys
input = sys.stdin.readline
def solve():
n, k = map(int, input().split())
a = list(map(int, input().split()))
d = [-1000000] * n
ans = 1000000
for i in range(0, n):
z = -1000000
v = a[i]
w = a[i] - i
if i >= v - 1:
z = 0
for j in range(i):
if a[j] < v and a[j] - j >= w:
z = max(z, d[j])
d[i] = z + 1
if z + 1 >= k:
ans = min(ans, 1 - w)
if ans >= 1000000:
print(-1)
else:
print(ans)
for i in range(int(input())):
solve() | IMPORT ASSIGN VAR VAR FUNC_DEF 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 BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR BIN_OP VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP NUMBER VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR |
Consider a sequence of integers $a_1, a_2, \ldots, a_n$. In one move, you can select any element of the sequence and delete it. After an element is deleted, all elements to the right are shifted to the left by $1$ position, so there are no empty spaces in the sequence. So after you make a move, the sequence's length decreases by $1$. The indices of the elements after the move are recalculated.
E. g. let the sequence be $a=[3, 2, 2, 1, 5]$. Let's select the element $a_3=2$ in a move. Then after the move the sequence will be equal to $a=[3, 2, 1, 5]$, so the $3$-rd element of the new sequence will be $a_3=1$ and the $4$-th element will be $a_4=5$.
You are given a sequence $a_1, a_2, \ldots, a_n$ and a number $k$. You need to find the minimum number of moves you have to make so that in the resulting sequence there will be at least $k$ elements that are equal to their indices, i. e. the resulting sequence $b_1, b_2, \ldots, b_m$ will contain at least $k$ indices $i$ such that $b_i = i$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases. Then $t$ test cases follow.
Each test case consists of two consecutive lines. The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 2000$). The second line contains a sequence of integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$). The numbers in the sequence are not necessarily different.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $2000$.
-----Output-----
For each test case output in a single line:
$-1$ if there's no desired move sequence;
otherwise, the integer $x$ ($0 \le x \le n$) β the minimum number of the moves to be made so that the resulting sequence will contain at least $k$ elements that are equal to their indices.
-----Examples-----
Input
4
7 6
1 1 2 3 4 5 6
5 2
5 1 3 2 3
5 2
5 5 5 5 4
8 4
1 2 3 3 2 2 5 5
Output
1
2
-1
2
-----Note-----
In the first test case the sequence doesn't satisfy the desired condition, but it can be provided by deleting the first element, hence the sequence will be $[1, 2, 3, 4, 5, 6]$ and $6$ elements will be equal to their indices.
In the second test case there are two ways to get the desired result in $2$ moves: the first one is to delete the $1$-st and the $3$-rd elements so that the sequence will be $[1, 2, 3]$ and have $3$ elements equal to their indices; the second way is to delete the $2$-nd and the $3$-rd elements to get the sequence $[5, 2, 3]$ with $2$ desired elements. | t = int(input())
for pro in range(t):
n, k = map(int, input().split())
a = list(map(int, input().split(" ")))
dp = [[(0) for i in range(n + 1)] for kk in range(n)]
dp[0][0] = 1 if a[0] == 1 else 0
for i in range(1, n):
for j in range(i + 2):
if a[i] == i + 1 - j:
dp[i][j] = max(1 + dp[i - 1][j], dp[i - 1][j - 1])
else:
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - 1])
ans = -1
for truck in range(n + 1):
if dp[-1][truck] >= k:
ans = truck
break
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR 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 STRING ASSIGN VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR BIN_OP BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR |
Consider a sequence of integers $a_1, a_2, \ldots, a_n$. In one move, you can select any element of the sequence and delete it. After an element is deleted, all elements to the right are shifted to the left by $1$ position, so there are no empty spaces in the sequence. So after you make a move, the sequence's length decreases by $1$. The indices of the elements after the move are recalculated.
E. g. let the sequence be $a=[3, 2, 2, 1, 5]$. Let's select the element $a_3=2$ in a move. Then after the move the sequence will be equal to $a=[3, 2, 1, 5]$, so the $3$-rd element of the new sequence will be $a_3=1$ and the $4$-th element will be $a_4=5$.
You are given a sequence $a_1, a_2, \ldots, a_n$ and a number $k$. You need to find the minimum number of moves you have to make so that in the resulting sequence there will be at least $k$ elements that are equal to their indices, i. e. the resulting sequence $b_1, b_2, \ldots, b_m$ will contain at least $k$ indices $i$ such that $b_i = i$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases. Then $t$ test cases follow.
Each test case consists of two consecutive lines. The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 2000$). The second line contains a sequence of integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$). The numbers in the sequence are not necessarily different.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $2000$.
-----Output-----
For each test case output in a single line:
$-1$ if there's no desired move sequence;
otherwise, the integer $x$ ($0 \le x \le n$) β the minimum number of the moves to be made so that the resulting sequence will contain at least $k$ elements that are equal to their indices.
-----Examples-----
Input
4
7 6
1 1 2 3 4 5 6
5 2
5 1 3 2 3
5 2
5 5 5 5 4
8 4
1 2 3 3 2 2 5 5
Output
1
2
-1
2
-----Note-----
In the first test case the sequence doesn't satisfy the desired condition, but it can be provided by deleting the first element, hence the sequence will be $[1, 2, 3, 4, 5, 6]$ and $6$ elements will be equal to their indices.
In the second test case there are two ways to get the desired result in $2$ moves: the first one is to delete the $1$-st and the $3$-rd elements so that the sequence will be $[1, 2, 3]$ and have $3$ elements equal to their indices; the second way is to delete the $2$-nd and the $3$-rd elements to get the sequence $[5, 2, 3]$ with $2$ desired elements. | import sys
input = sys.stdin.readline
t = int(input())
for tests in range(t):
n, k = map(int, input().split())
A = list(map(int, input().split()))
B = [(i + 1 - A[i]) for i in range(n)]
DP = [-1] * (n + 2)
DP[0] = 0
for i in range(n):
for j in range(n, -1, -1):
if DP[j] != -1:
DP[j + 1] = max(DP[j], DP[j + 1])
if B[i] == j:
DP[j] += 1
for i in range(n + 2):
if DP[i] >= k:
print(i)
break
else:
print(-1) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR 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 BIN_OP BIN_OP VAR NUMBER VAR VAR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER |
Consider a sequence of integers $a_1, a_2, \ldots, a_n$. In one move, you can select any element of the sequence and delete it. After an element is deleted, all elements to the right are shifted to the left by $1$ position, so there are no empty spaces in the sequence. So after you make a move, the sequence's length decreases by $1$. The indices of the elements after the move are recalculated.
E. g. let the sequence be $a=[3, 2, 2, 1, 5]$. Let's select the element $a_3=2$ in a move. Then after the move the sequence will be equal to $a=[3, 2, 1, 5]$, so the $3$-rd element of the new sequence will be $a_3=1$ and the $4$-th element will be $a_4=5$.
You are given a sequence $a_1, a_2, \ldots, a_n$ and a number $k$. You need to find the minimum number of moves you have to make so that in the resulting sequence there will be at least $k$ elements that are equal to their indices, i. e. the resulting sequence $b_1, b_2, \ldots, b_m$ will contain at least $k$ indices $i$ such that $b_i = i$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases. Then $t$ test cases follow.
Each test case consists of two consecutive lines. The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 2000$). The second line contains a sequence of integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$). The numbers in the sequence are not necessarily different.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $2000$.
-----Output-----
For each test case output in a single line:
$-1$ if there's no desired move sequence;
otherwise, the integer $x$ ($0 \le x \le n$) β the minimum number of the moves to be made so that the resulting sequence will contain at least $k$ elements that are equal to their indices.
-----Examples-----
Input
4
7 6
1 1 2 3 4 5 6
5 2
5 1 3 2 3
5 2
5 5 5 5 4
8 4
1 2 3 3 2 2 5 5
Output
1
2
-1
2
-----Note-----
In the first test case the sequence doesn't satisfy the desired condition, but it can be provided by deleting the first element, hence the sequence will be $[1, 2, 3, 4, 5, 6]$ and $6$ elements will be equal to their indices.
In the second test case there are two ways to get the desired result in $2$ moves: the first one is to delete the $1$-st and the $3$-rd elements so that the sequence will be $[1, 2, 3]$ and have $3$ elements equal to their indices; the second way is to delete the $2$-nd and the $3$-rd elements to get the sequence $[5, 2, 3]$ with $2$ desired elements. | import sys
input = sys.stdin.readline
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
a = list(map(int, input().split()))
dp = [([0] * (n + 1)) for i in range(n + 1)]
for i in range(n):
for j in range(i + 1):
dp[i + 1][j] = max(dp[i + 1][j], dp[i][j])
dp[i + 1][j + 1] = max(dp[i + 1][j + 1], dp[i][j] + (a[i] == j + 1))
ans = -1
for i in range(n + 1)[::-1]:
if dp[n][i] >= k:
ans = n - i
break
print(ans) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR 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 BIN_OP LIST NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR |
Consider a sequence of integers $a_1, a_2, \ldots, a_n$. In one move, you can select any element of the sequence and delete it. After an element is deleted, all elements to the right are shifted to the left by $1$ position, so there are no empty spaces in the sequence. So after you make a move, the sequence's length decreases by $1$. The indices of the elements after the move are recalculated.
E. g. let the sequence be $a=[3, 2, 2, 1, 5]$. Let's select the element $a_3=2$ in a move. Then after the move the sequence will be equal to $a=[3, 2, 1, 5]$, so the $3$-rd element of the new sequence will be $a_3=1$ and the $4$-th element will be $a_4=5$.
You are given a sequence $a_1, a_2, \ldots, a_n$ and a number $k$. You need to find the minimum number of moves you have to make so that in the resulting sequence there will be at least $k$ elements that are equal to their indices, i. e. the resulting sequence $b_1, b_2, \ldots, b_m$ will contain at least $k$ indices $i$ such that $b_i = i$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases. Then $t$ test cases follow.
Each test case consists of two consecutive lines. The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 2000$). The second line contains a sequence of integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$). The numbers in the sequence are not necessarily different.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $2000$.
-----Output-----
For each test case output in a single line:
$-1$ if there's no desired move sequence;
otherwise, the integer $x$ ($0 \le x \le n$) β the minimum number of the moves to be made so that the resulting sequence will contain at least $k$ elements that are equal to their indices.
-----Examples-----
Input
4
7 6
1 1 2 3 4 5 6
5 2
5 1 3 2 3
5 2
5 5 5 5 4
8 4
1 2 3 3 2 2 5 5
Output
1
2
-1
2
-----Note-----
In the first test case the sequence doesn't satisfy the desired condition, but it can be provided by deleting the first element, hence the sequence will be $[1, 2, 3, 4, 5, 6]$ and $6$ elements will be equal to their indices.
In the second test case there are two ways to get the desired result in $2$ moves: the first one is to delete the $1$-st and the $3$-rd elements so that the sequence will be $[1, 2, 3]$ and have $3$ elements equal to their indices; the second way is to delete the $2$-nd and the $3$-rd elements to get the sequence $[5, 2, 3]$ with $2$ desired elements. | INF = 1001001001
def main():
N, K = map(int, input().split())
A = list(map(lambda x: int(x) - 1, input().split()))
DP = [([-INF] * (N + 1)) for _ in range(N + 1)]
DP[0][0] = 0
for i in range(N):
for j in range(N):
if A[i] == j:
DP[i + 1][j + 1] = max(DP[i + 1][j + 1], DP[i][j] + 1)
else:
DP[i + 1][j + 1] = max(DP[i + 1][j + 1], DP[i][j])
DP[i + 1][j] = max(DP[i + 1][j], DP[i][j])
Ans = INF
for i in range(N + 1):
if DP[N][i] >= K:
Ans = N - i
print(Ans if Ans != INF else -1)
T = int(input())
for _ in range(T):
main() | ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR |
Consider a sequence of integers $a_1, a_2, \ldots, a_n$. In one move, you can select any element of the sequence and delete it. After an element is deleted, all elements to the right are shifted to the left by $1$ position, so there are no empty spaces in the sequence. So after you make a move, the sequence's length decreases by $1$. The indices of the elements after the move are recalculated.
E. g. let the sequence be $a=[3, 2, 2, 1, 5]$. Let's select the element $a_3=2$ in a move. Then after the move the sequence will be equal to $a=[3, 2, 1, 5]$, so the $3$-rd element of the new sequence will be $a_3=1$ and the $4$-th element will be $a_4=5$.
You are given a sequence $a_1, a_2, \ldots, a_n$ and a number $k$. You need to find the minimum number of moves you have to make so that in the resulting sequence there will be at least $k$ elements that are equal to their indices, i. e. the resulting sequence $b_1, b_2, \ldots, b_m$ will contain at least $k$ indices $i$ such that $b_i = i$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases. Then $t$ test cases follow.
Each test case consists of two consecutive lines. The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 2000$). The second line contains a sequence of integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$). The numbers in the sequence are not necessarily different.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $2000$.
-----Output-----
For each test case output in a single line:
$-1$ if there's no desired move sequence;
otherwise, the integer $x$ ($0 \le x \le n$) β the minimum number of the moves to be made so that the resulting sequence will contain at least $k$ elements that are equal to their indices.
-----Examples-----
Input
4
7 6
1 1 2 3 4 5 6
5 2
5 1 3 2 3
5 2
5 5 5 5 4
8 4
1 2 3 3 2 2 5 5
Output
1
2
-1
2
-----Note-----
In the first test case the sequence doesn't satisfy the desired condition, but it can be provided by deleting the first element, hence the sequence will be $[1, 2, 3, 4, 5, 6]$ and $6$ elements will be equal to their indices.
In the second test case there are two ways to get the desired result in $2$ moves: the first one is to delete the $1$-st and the $3$-rd elements so that the sequence will be $[1, 2, 3]$ and have $3$ elements equal to their indices; the second way is to delete the $2$-nd and the $3$-rd elements to get the sequence $[5, 2, 3]$ with $2$ desired elements. | import sys
input = sys.stdin.readline
def main():
INF = 10**5
t = int(input())
for _ in range(t):
n, k = map(int, input().split())
ar = list(map(int, input().split()))
dp = [[(0) for _ in range(n + 5)] for _ in range(n + 5)]
ans = INF
for i in range(1, n + 1):
for j in range(1, i + 1):
dp[i][j] = dp[i - 1][j]
if ar[i - 1] == j:
dp[i][j] = max(dp[i][j], dp[i - 1][j - 1] + 1)
else:
dp[i][j] = max(dp[i][j], dp[i - 1][j - 1])
if dp[i][j] >= k:
ans = min(ans, i - j)
if ans < INF:
print(ans)
else:
print(-1)
main() | IMPORT ASSIGN VAR VAR FUNC_DEF ASSIGN VAR BIN_OP NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR 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 NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR BIN_OP VAR NUMBER VAR IF VAR BIN_OP VAR NUMBER VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER IF VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR |
Consider a sequence of integers $a_1, a_2, \ldots, a_n$. In one move, you can select any element of the sequence and delete it. After an element is deleted, all elements to the right are shifted to the left by $1$ position, so there are no empty spaces in the sequence. So after you make a move, the sequence's length decreases by $1$. The indices of the elements after the move are recalculated.
E. g. let the sequence be $a=[3, 2, 2, 1, 5]$. Let's select the element $a_3=2$ in a move. Then after the move the sequence will be equal to $a=[3, 2, 1, 5]$, so the $3$-rd element of the new sequence will be $a_3=1$ and the $4$-th element will be $a_4=5$.
You are given a sequence $a_1, a_2, \ldots, a_n$ and a number $k$. You need to find the minimum number of moves you have to make so that in the resulting sequence there will be at least $k$ elements that are equal to their indices, i. e. the resulting sequence $b_1, b_2, \ldots, b_m$ will contain at least $k$ indices $i$ such that $b_i = i$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases. Then $t$ test cases follow.
Each test case consists of two consecutive lines. The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 2000$). The second line contains a sequence of integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$). The numbers in the sequence are not necessarily different.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $2000$.
-----Output-----
For each test case output in a single line:
$-1$ if there's no desired move sequence;
otherwise, the integer $x$ ($0 \le x \le n$) β the minimum number of the moves to be made so that the resulting sequence will contain at least $k$ elements that are equal to their indices.
-----Examples-----
Input
4
7 6
1 1 2 3 4 5 6
5 2
5 1 3 2 3
5 2
5 5 5 5 4
8 4
1 2 3 3 2 2 5 5
Output
1
2
-1
2
-----Note-----
In the first test case the sequence doesn't satisfy the desired condition, but it can be provided by deleting the first element, hence the sequence will be $[1, 2, 3, 4, 5, 6]$ and $6$ elements will be equal to their indices.
In the second test case there are two ways to get the desired result in $2$ moves: the first one is to delete the $1$-st and the $3$-rd elements so that the sequence will be $[1, 2, 3]$ and have $3$ elements equal to their indices; the second way is to delete the $2$-nd and the $3$-rd elements to get the sequence $[5, 2, 3]$ with $2$ desired elements. | NUM = int(input())
for T in range(0, NUM):
N, K = map(int, input().split())
numlist = list(map(int, input().split()))
for i in range(0, N):
numlist[i] -= i + 1
dp = []
ans = 10**10
for i in range(0, N):
mx = 1
for j in range(0, i):
if numlist[j] >= numlist[i] and numlist[j] - numlist[i] < i - j:
mx = max(mx, dp[j] + 1)
if numlist[i] > 0:
mx = -N
dp.append(mx)
if mx == K:
ans = min(ans, -numlist[i])
if ans == 10**10:
print(-1)
else:
print(ans) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER 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 FOR VAR FUNC_CALL VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR BIN_OP NUMBER NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR |
Consider a sequence of integers $a_1, a_2, \ldots, a_n$. In one move, you can select any element of the sequence and delete it. After an element is deleted, all elements to the right are shifted to the left by $1$ position, so there are no empty spaces in the sequence. So after you make a move, the sequence's length decreases by $1$. The indices of the elements after the move are recalculated.
E. g. let the sequence be $a=[3, 2, 2, 1, 5]$. Let's select the element $a_3=2$ in a move. Then after the move the sequence will be equal to $a=[3, 2, 1, 5]$, so the $3$-rd element of the new sequence will be $a_3=1$ and the $4$-th element will be $a_4=5$.
You are given a sequence $a_1, a_2, \ldots, a_n$ and a number $k$. You need to find the minimum number of moves you have to make so that in the resulting sequence there will be at least $k$ elements that are equal to their indices, i. e. the resulting sequence $b_1, b_2, \ldots, b_m$ will contain at least $k$ indices $i$ such that $b_i = i$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases. Then $t$ test cases follow.
Each test case consists of two consecutive lines. The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 2000$). The second line contains a sequence of integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$). The numbers in the sequence are not necessarily different.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $2000$.
-----Output-----
For each test case output in a single line:
$-1$ if there's no desired move sequence;
otherwise, the integer $x$ ($0 \le x \le n$) β the minimum number of the moves to be made so that the resulting sequence will contain at least $k$ elements that are equal to their indices.
-----Examples-----
Input
4
7 6
1 1 2 3 4 5 6
5 2
5 1 3 2 3
5 2
5 5 5 5 4
8 4
1 2 3 3 2 2 5 5
Output
1
2
-1
2
-----Note-----
In the first test case the sequence doesn't satisfy the desired condition, but it can be provided by deleting the first element, hence the sequence will be $[1, 2, 3, 4, 5, 6]$ and $6$ elements will be equal to their indices.
In the second test case there are two ways to get the desired result in $2$ moves: the first one is to delete the $1$-st and the $3$-rd elements so that the sequence will be $[1, 2, 3]$ and have $3$ elements equal to their indices; the second way is to delete the $2$-nd and the $3$-rd elements to get the sequence $[5, 2, 3]$ with $2$ desired elements. | import sys
input = sys.stdin.readline
def solve():
n, k = map(int, input().split())
A = list(map(int, input().split()))
A = [(x - 1) for x in A]
dp = [([-1 << 32] * (n + 1)) for _ in range(n + 1)]
dp[0][0] = 0
dp[0][1] = int(A[0] == 0)
for i in range(1, n):
for j in range(i + 2):
if j == 0:
dp[i][j] = 0
continue
drop = dp[i - 1][j]
keep = dp[i - 1][j - 1] + int(A[i] == j - 1)
dp[i][j] = max(drop, keep)
for j in range(n, -1, -1):
if dp[n - 1][j] >= k:
print(n - j)
return
print(-1)
return
for nt in range(int(input())):
solve() | IMPORT ASSIGN VAR VAR FUNC_DEF 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 BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP LIST BIN_OP NUMBER NUMBER BIN_OP VAR NUMBER VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER NUMBER NUMBER ASSIGN VAR NUMBER NUMBER FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR FUNC_CALL VAR VAR VAR FOR VAR FUNC_CALL VAR VAR NUMBER NUMBER IF VAR BIN_OP VAR NUMBER VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR RETURN EXPR FUNC_CALL VAR NUMBER RETURN FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR |
Consider a sequence of integers $a_1, a_2, \ldots, a_n$. In one move, you can select any element of the sequence and delete it. After an element is deleted, all elements to the right are shifted to the left by $1$ position, so there are no empty spaces in the sequence. So after you make a move, the sequence's length decreases by $1$. The indices of the elements after the move are recalculated.
E. g. let the sequence be $a=[3, 2, 2, 1, 5]$. Let's select the element $a_3=2$ in a move. Then after the move the sequence will be equal to $a=[3, 2, 1, 5]$, so the $3$-rd element of the new sequence will be $a_3=1$ and the $4$-th element will be $a_4=5$.
You are given a sequence $a_1, a_2, \ldots, a_n$ and a number $k$. You need to find the minimum number of moves you have to make so that in the resulting sequence there will be at least $k$ elements that are equal to their indices, i. e. the resulting sequence $b_1, b_2, \ldots, b_m$ will contain at least $k$ indices $i$ such that $b_i = i$.
-----Input-----
The first line contains one integer $t$ ($1 \le t \le 100$) β the number of test cases. Then $t$ test cases follow.
Each test case consists of two consecutive lines. The first line contains two integers $n$ and $k$ ($1 \le k \le n \le 2000$). The second line contains a sequence of integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le n$). The numbers in the sequence are not necessarily different.
It is guaranteed that the sum of $n$ over all test cases doesn't exceed $2000$.
-----Output-----
For each test case output in a single line:
$-1$ if there's no desired move sequence;
otherwise, the integer $x$ ($0 \le x \le n$) β the minimum number of the moves to be made so that the resulting sequence will contain at least $k$ elements that are equal to their indices.
-----Examples-----
Input
4
7 6
1 1 2 3 4 5 6
5 2
5 1 3 2 3
5 2
5 5 5 5 4
8 4
1 2 3 3 2 2 5 5
Output
1
2
-1
2
-----Note-----
In the first test case the sequence doesn't satisfy the desired condition, but it can be provided by deleting the first element, hence the sequence will be $[1, 2, 3, 4, 5, 6]$ and $6$ elements will be equal to their indices.
In the second test case there are two ways to get the desired result in $2$ moves: the first one is to delete the $1$-st and the $3$-rd elements so that the sequence will be $[1, 2, 3]$ and have $3$ elements equal to their indices; the second way is to delete the $2$-nd and the $3$-rd elements to get the sequence $[5, 2, 3]$ with $2$ desired elements. | import sys
input = sys.stdin.readline
al3 = list("abcdefghijklmnopqrstuvwx")
al2 = ["y", "z"]
t = int(input())
for iii in range(t):
n, k = map(int, input().split())
a = [0] + list(map(int, input().split()))
dp = [-(10**18)] * (n + 3) * (n + 3)
def _(i, j):
return i * (n + 1) + j
dp[_(0, 0)] = 0
for i in range(1, n + 1):
for j in range(i + 1):
dp[_(i, j)] = dp[_(i - 1, j)]
if a[i] == i - j:
dp[_(i, j)] = max(dp[_(i, j)], dp[_(i - 1, j)] + 1)
if j >= 1:
dp[_(i, j)] = max(dp[_(i, j)], dp[_(i - 1, j - 1)])
ans = 10**18
for i in range(n + 1):
if dp[_(n, i)] >= k:
ans = min(ans, i)
print(ans if ans < 10**18 else -1) | IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR LIST STRING STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP LIST BIN_OP NUMBER NUMBER BIN_OP VAR NUMBER BIN_OP VAR NUMBER FUNC_DEF RETURN BIN_OP BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR BIN_OP VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR BIN_OP VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER IF VAR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR BIN_OP NUMBER NUMBER VAR NUMBER |
There are $n$ astronauts working on some space station. An astronaut with the number $i$ ($1 \le i \le n$) has power $a_i$.
An evil humanoid has made his way to this space station. The power of this humanoid is equal to $h$. Also, the humanoid took with him two green serums and one blue serum.
In one second , a humanoid can do any of three actions:
to absorb an astronaut with power strictly less humanoid power;
to use green serum, if there is still one left;
to use blue serum, if there is still one left.
When an astronaut with power $a_i$ is absorbed, this astronaut disappears, and power of the humanoid increases by $\lfloor \frac{a_i}{2} \rfloor$, that is, an integer part of $\frac{a_i}{2}$. For example, if a humanoid absorbs an astronaut with power $4$, its power increases by $2$, and if a humanoid absorbs an astronaut with power $7$, its power increases by $3$.
After using the green serum, this serum disappears, and the power of the humanoid doubles, so it increases by $2$ times.
After using the blue serum, this serum disappears, and the power of the humanoid triples, so it increases by $3$ times.
The humanoid is wondering what the maximum number of astronauts he will be able to absorb if he acts optimally.
-----Input-----
The first line of each test contains an integer $t$ ($1 \le t \le 10^4$) β number of test cases.
The first line of each test case contains integers $n$ ($1 \le n \le 2 \cdot 10^5$) β number of astronauts and $h$ ($1 \le h \le 10^6$) β the initial power of the humanoid.
The second line of each test case contains $n$ integers $a_i$ ($1 \le a_i \le 10^8$) β powers of astronauts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, in a separate line, print the maximum number of astronauts that a humanoid can absorb.
-----Examples-----
Input
8
4 1
2 1 8 9
3 3
6 2 60
4 5
5 1 100 5
3 2
38 6 3
1 1
12
4 6
12 12 36 100
4 1
2 1 1 15
3 5
15 1 13
Output
4
3
3
3
0
4
4
3
-----Note-----
In the first case, you can proceed as follows:
use green serum. $h = 1 \cdot 2 = 2$
absorb the cosmonaut $2$. $h = 2 + \lfloor \frac{1}{2} \rfloor = 2$
use green serum. $h = 2 \cdot 2 = 4$
absorb the spaceman $1$. $h = 4 + \lfloor \frac{2}{2} \rfloor = 5$
use blue serum. $h = 5 \cdot 3 = 15$
absorb the spaceman $3$. $h = 15 + \lfloor \frac{8}{2} \rfloor = 19$
absorb the cosmonaut $4$. $h = 19 + \lfloor \frac{9}{2} \rfloor = 23$ | T = int(input())
def best(h, astro, serum_order):
absorbed = 0
serum_index = 0
for p in astro:
while p >= h:
if serum_index == 3:
return absorbed
h *= serum_order[serum_index]
serum_index += 1
absorbed += 1
h += p // 2
return absorbed
for _ in range(T):
n, h = map(int, input().split())
astro = list(map(int, input().split()))
astro.sort()
print(
max(
best(h, astro, (3, 2, 2)),
best(h, astro, (2, 3, 2)),
best(h, astro, (2, 2, 3)),
)
) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR WHILE VAR VAR IF VAR NUMBER RETURN VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR 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 EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER NUMBER NUMBER FUNC_CALL VAR VAR VAR NUMBER NUMBER NUMBER FUNC_CALL VAR VAR VAR NUMBER NUMBER NUMBER |
There are $n$ astronauts working on some space station. An astronaut with the number $i$ ($1 \le i \le n$) has power $a_i$.
An evil humanoid has made his way to this space station. The power of this humanoid is equal to $h$. Also, the humanoid took with him two green serums and one blue serum.
In one second , a humanoid can do any of three actions:
to absorb an astronaut with power strictly less humanoid power;
to use green serum, if there is still one left;
to use blue serum, if there is still one left.
When an astronaut with power $a_i$ is absorbed, this astronaut disappears, and power of the humanoid increases by $\lfloor \frac{a_i}{2} \rfloor$, that is, an integer part of $\frac{a_i}{2}$. For example, if a humanoid absorbs an astronaut with power $4$, its power increases by $2$, and if a humanoid absorbs an astronaut with power $7$, its power increases by $3$.
After using the green serum, this serum disappears, and the power of the humanoid doubles, so it increases by $2$ times.
After using the blue serum, this serum disappears, and the power of the humanoid triples, so it increases by $3$ times.
The humanoid is wondering what the maximum number of astronauts he will be able to absorb if he acts optimally.
-----Input-----
The first line of each test contains an integer $t$ ($1 \le t \le 10^4$) β number of test cases.
The first line of each test case contains integers $n$ ($1 \le n \le 2 \cdot 10^5$) β number of astronauts and $h$ ($1 \le h \le 10^6$) β the initial power of the humanoid.
The second line of each test case contains $n$ integers $a_i$ ($1 \le a_i \le 10^8$) β powers of astronauts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, in a separate line, print the maximum number of astronauts that a humanoid can absorb.
-----Examples-----
Input
8
4 1
2 1 8 9
3 3
6 2 60
4 5
5 1 100 5
3 2
38 6 3
1 1
12
4 6
12 12 36 100
4 1
2 1 1 15
3 5
15 1 13
Output
4
3
3
3
0
4
4
3
-----Note-----
In the first case, you can proceed as follows:
use green serum. $h = 1 \cdot 2 = 2$
absorb the cosmonaut $2$. $h = 2 + \lfloor \frac{1}{2} \rfloor = 2$
use green serum. $h = 2 \cdot 2 = 4$
absorb the spaceman $1$. $h = 4 + \lfloor \frac{2}{2} \rfloor = 5$
use blue serum. $h = 5 \cdot 3 = 15$
absorb the spaceman $3$. $h = 15 + \lfloor \frac{8}{2} \rfloor = 19$
absorb the cosmonaut $4$. $h = 19 + \lfloor \frac{9}{2} \rfloor = 23$ | T = int(input())
poss = (2, 2, 3), (2, 3, 2), (3, 2, 2)
for _ in range(T):
n, rawh = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
m = []
for s in poss:
hum = 0
ct = 0
h = rawh
for p in a:
while h <= p and ct <= 2:
h *= s[ct]
ct += 1
if h <= p and ct == 3:
break
h += p // 2
hum += 1
m.append(hum)
print(max(m)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR 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 EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR VAR WHILE VAR VAR VAR NUMBER VAR VAR VAR VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
There are $n$ astronauts working on some space station. An astronaut with the number $i$ ($1 \le i \le n$) has power $a_i$.
An evil humanoid has made his way to this space station. The power of this humanoid is equal to $h$. Also, the humanoid took with him two green serums and one blue serum.
In one second , a humanoid can do any of three actions:
to absorb an astronaut with power strictly less humanoid power;
to use green serum, if there is still one left;
to use blue serum, if there is still one left.
When an astronaut with power $a_i$ is absorbed, this astronaut disappears, and power of the humanoid increases by $\lfloor \frac{a_i}{2} \rfloor$, that is, an integer part of $\frac{a_i}{2}$. For example, if a humanoid absorbs an astronaut with power $4$, its power increases by $2$, and if a humanoid absorbs an astronaut with power $7$, its power increases by $3$.
After using the green serum, this serum disappears, and the power of the humanoid doubles, so it increases by $2$ times.
After using the blue serum, this serum disappears, and the power of the humanoid triples, so it increases by $3$ times.
The humanoid is wondering what the maximum number of astronauts he will be able to absorb if he acts optimally.
-----Input-----
The first line of each test contains an integer $t$ ($1 \le t \le 10^4$) β number of test cases.
The first line of each test case contains integers $n$ ($1 \le n \le 2 \cdot 10^5$) β number of astronauts and $h$ ($1 \le h \le 10^6$) β the initial power of the humanoid.
The second line of each test case contains $n$ integers $a_i$ ($1 \le a_i \le 10^8$) β powers of astronauts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, in a separate line, print the maximum number of astronauts that a humanoid can absorb.
-----Examples-----
Input
8
4 1
2 1 8 9
3 3
6 2 60
4 5
5 1 100 5
3 2
38 6 3
1 1
12
4 6
12 12 36 100
4 1
2 1 1 15
3 5
15 1 13
Output
4
3
3
3
0
4
4
3
-----Note-----
In the first case, you can proceed as follows:
use green serum. $h = 1 \cdot 2 = 2$
absorb the cosmonaut $2$. $h = 2 + \lfloor \frac{1}{2} \rfloor = 2$
use green serum. $h = 2 \cdot 2 = 4$
absorb the spaceman $1$. $h = 4 + \lfloor \frac{2}{2} \rfloor = 5$
use blue serum. $h = 5 \cdot 3 = 15$
absorb the spaceman $3$. $h = 15 + \lfloor \frac{8}{2} \rfloor = 19$
absorb the cosmonaut $4$. $h = 19 + \lfloor \frac{9}{2} \rfloor = 23$ | t = int(input())
for i in range(t):
n, h = map(int, input().split())
a = [int(x) for x in input().split()]
a.sort()
number = 0
for i in range(3):
h0 = 0
num = 0
serum = 3
h1 = h
while h0 < n and serum >= 0:
if a[h0] < h1:
num += 1
h1 += int(a[h0]) // 2
h0 += 1
continue
if a[h0] >= h1:
if serum == i + 1:
h1 = 3 * h1
serum -= 1
continue
else:
h1 = 2 * h1
serum -= 1
continue
number = max(num, number)
print(number) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR 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 EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR IF VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR BIN_OP NUMBER VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
There are $n$ astronauts working on some space station. An astronaut with the number $i$ ($1 \le i \le n$) has power $a_i$.
An evil humanoid has made his way to this space station. The power of this humanoid is equal to $h$. Also, the humanoid took with him two green serums and one blue serum.
In one second , a humanoid can do any of three actions:
to absorb an astronaut with power strictly less humanoid power;
to use green serum, if there is still one left;
to use blue serum, if there is still one left.
When an astronaut with power $a_i$ is absorbed, this astronaut disappears, and power of the humanoid increases by $\lfloor \frac{a_i}{2} \rfloor$, that is, an integer part of $\frac{a_i}{2}$. For example, if a humanoid absorbs an astronaut with power $4$, its power increases by $2$, and if a humanoid absorbs an astronaut with power $7$, its power increases by $3$.
After using the green serum, this serum disappears, and the power of the humanoid doubles, so it increases by $2$ times.
After using the blue serum, this serum disappears, and the power of the humanoid triples, so it increases by $3$ times.
The humanoid is wondering what the maximum number of astronauts he will be able to absorb if he acts optimally.
-----Input-----
The first line of each test contains an integer $t$ ($1 \le t \le 10^4$) β number of test cases.
The first line of each test case contains integers $n$ ($1 \le n \le 2 \cdot 10^5$) β number of astronauts and $h$ ($1 \le h \le 10^6$) β the initial power of the humanoid.
The second line of each test case contains $n$ integers $a_i$ ($1 \le a_i \le 10^8$) β powers of astronauts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, in a separate line, print the maximum number of astronauts that a humanoid can absorb.
-----Examples-----
Input
8
4 1
2 1 8 9
3 3
6 2 60
4 5
5 1 100 5
3 2
38 6 3
1 1
12
4 6
12 12 36 100
4 1
2 1 1 15
3 5
15 1 13
Output
4
3
3
3
0
4
4
3
-----Note-----
In the first case, you can proceed as follows:
use green serum. $h = 1 \cdot 2 = 2$
absorb the cosmonaut $2$. $h = 2 + \lfloor \frac{1}{2} \rfloor = 2$
use green serum. $h = 2 \cdot 2 = 4$
absorb the spaceman $1$. $h = 4 + \lfloor \frac{2}{2} \rfloor = 5$
use blue serum. $h = 5 \cdot 3 = 15$
absorb the spaceman $3$. $h = 15 + \lfloor \frac{8}{2} \rfloor = 19$
absorb the cosmonaut $4$. $h = 19 + \lfloor \frac{9}{2} \rfloor = 23$ | test = int(input())
while test:
test -= 1
n, m = map(int, input().split())
a = list(map(int, input().split()))
a = sorted(a)
ls = [[0, 1, 1], [1, 0, 1], [1, 1, 0]]
mx = 0
for x in ls:
s = 0
l = 0
temp = m
for i in a:
while i >= temp:
if l < 3:
if x[l] == 1:
temp *= 2
else:
temp *= 3
l += 1
if l == 3:
break
if i < temp:
s += 1
temp += i // 2
mx = max(mx, s)
print(mx) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR VAR NUMBER 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 FUNC_CALL VAR VAR ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER ASSIGN VAR NUMBER FOR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR VAR WHILE VAR VAR IF VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER IF VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
There are $n$ astronauts working on some space station. An astronaut with the number $i$ ($1 \le i \le n$) has power $a_i$.
An evil humanoid has made his way to this space station. The power of this humanoid is equal to $h$. Also, the humanoid took with him two green serums and one blue serum.
In one second , a humanoid can do any of three actions:
to absorb an astronaut with power strictly less humanoid power;
to use green serum, if there is still one left;
to use blue serum, if there is still one left.
When an astronaut with power $a_i$ is absorbed, this astronaut disappears, and power of the humanoid increases by $\lfloor \frac{a_i}{2} \rfloor$, that is, an integer part of $\frac{a_i}{2}$. For example, if a humanoid absorbs an astronaut with power $4$, its power increases by $2$, and if a humanoid absorbs an astronaut with power $7$, its power increases by $3$.
After using the green serum, this serum disappears, and the power of the humanoid doubles, so it increases by $2$ times.
After using the blue serum, this serum disappears, and the power of the humanoid triples, so it increases by $3$ times.
The humanoid is wondering what the maximum number of astronauts he will be able to absorb if he acts optimally.
-----Input-----
The first line of each test contains an integer $t$ ($1 \le t \le 10^4$) β number of test cases.
The first line of each test case contains integers $n$ ($1 \le n \le 2 \cdot 10^5$) β number of astronauts and $h$ ($1 \le h \le 10^6$) β the initial power of the humanoid.
The second line of each test case contains $n$ integers $a_i$ ($1 \le a_i \le 10^8$) β powers of astronauts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, in a separate line, print the maximum number of astronauts that a humanoid can absorb.
-----Examples-----
Input
8
4 1
2 1 8 9
3 3
6 2 60
4 5
5 1 100 5
3 2
38 6 3
1 1
12
4 6
12 12 36 100
4 1
2 1 1 15
3 5
15 1 13
Output
4
3
3
3
0
4
4
3
-----Note-----
In the first case, you can proceed as follows:
use green serum. $h = 1 \cdot 2 = 2$
absorb the cosmonaut $2$. $h = 2 + \lfloor \frac{1}{2} \rfloor = 2$
use green serum. $h = 2 \cdot 2 = 4$
absorb the spaceman $1$. $h = 4 + \lfloor \frac{2}{2} \rfloor = 5$
use blue serum. $h = 5 \cdot 3 = 15$
absorb the spaceman $3$. $h = 15 + \lfloor \frac{8}{2} \rfloor = 19$
absorb the cosmonaut $4$. $h = 19 + \lfloor \frac{9}{2} \rfloor = 23$ | t = int(input())
for _ in range(t):
n, h = map(int, input().split())
L0 = list(map(int, input().split()))
L = sorted(L0)
count = 0
for l in range(3):
H = h
ct = 0
i0 = 0
for p in range(4):
while i0 < n and L[i0] < H:
H += L[i0] // 2
ct += 1
i0 += 1
if p == l:
H *= 3
else:
H *= 2
count = max(count, ct)
print(count) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR 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 FUNC_CALL VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
There are $n$ astronauts working on some space station. An astronaut with the number $i$ ($1 \le i \le n$) has power $a_i$.
An evil humanoid has made his way to this space station. The power of this humanoid is equal to $h$. Also, the humanoid took with him two green serums and one blue serum.
In one second , a humanoid can do any of three actions:
to absorb an astronaut with power strictly less humanoid power;
to use green serum, if there is still one left;
to use blue serum, if there is still one left.
When an astronaut with power $a_i$ is absorbed, this astronaut disappears, and power of the humanoid increases by $\lfloor \frac{a_i}{2} \rfloor$, that is, an integer part of $\frac{a_i}{2}$. For example, if a humanoid absorbs an astronaut with power $4$, its power increases by $2$, and if a humanoid absorbs an astronaut with power $7$, its power increases by $3$.
After using the green serum, this serum disappears, and the power of the humanoid doubles, so it increases by $2$ times.
After using the blue serum, this serum disappears, and the power of the humanoid triples, so it increases by $3$ times.
The humanoid is wondering what the maximum number of astronauts he will be able to absorb if he acts optimally.
-----Input-----
The first line of each test contains an integer $t$ ($1 \le t \le 10^4$) β number of test cases.
The first line of each test case contains integers $n$ ($1 \le n \le 2 \cdot 10^5$) β number of astronauts and $h$ ($1 \le h \le 10^6$) β the initial power of the humanoid.
The second line of each test case contains $n$ integers $a_i$ ($1 \le a_i \le 10^8$) β powers of astronauts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, in a separate line, print the maximum number of astronauts that a humanoid can absorb.
-----Examples-----
Input
8
4 1
2 1 8 9
3 3
6 2 60
4 5
5 1 100 5
3 2
38 6 3
1 1
12
4 6
12 12 36 100
4 1
2 1 1 15
3 5
15 1 13
Output
4
3
3
3
0
4
4
3
-----Note-----
In the first case, you can proceed as follows:
use green serum. $h = 1 \cdot 2 = 2$
absorb the cosmonaut $2$. $h = 2 + \lfloor \frac{1}{2} \rfloor = 2$
use green serum. $h = 2 \cdot 2 = 4$
absorb the spaceman $1$. $h = 4 + \lfloor \frac{2}{2} \rfloor = 5$
use blue serum. $h = 5 \cdot 3 = 15$
absorb the spaceman $3$. $h = 15 + \lfloor \frac{8}{2} \rfloor = 19$
absorb the cosmonaut $4$. $h = 19 + \lfloor \frac{9}{2} \rfloor = 23$ | t = int(input(""))
C = [0] * t
for i in range(t):
LRX = input("").split(" ")
n = int(LRX[0])
h0 = int(LRX[1])
A = sorted([int(x) for x in input("").split(" ")])
s = 0
for j in range(3):
h = h0
k = 0
for z in range(4):
while k < n and h > A[k]:
h += A[k] // 2
k += 1
if z == j:
h *= 3
else:
h *= 2
s = max(s, k)
C[i] = s
for j in C:
print(j) | 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 FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING STRING ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER WHILE VAR VAR VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR FOR VAR VAR EXPR FUNC_CALL VAR VAR |
There are $n$ astronauts working on some space station. An astronaut with the number $i$ ($1 \le i \le n$) has power $a_i$.
An evil humanoid has made his way to this space station. The power of this humanoid is equal to $h$. Also, the humanoid took with him two green serums and one blue serum.
In one second , a humanoid can do any of three actions:
to absorb an astronaut with power strictly less humanoid power;
to use green serum, if there is still one left;
to use blue serum, if there is still one left.
When an astronaut with power $a_i$ is absorbed, this astronaut disappears, and power of the humanoid increases by $\lfloor \frac{a_i}{2} \rfloor$, that is, an integer part of $\frac{a_i}{2}$. For example, if a humanoid absorbs an astronaut with power $4$, its power increases by $2$, and if a humanoid absorbs an astronaut with power $7$, its power increases by $3$.
After using the green serum, this serum disappears, and the power of the humanoid doubles, so it increases by $2$ times.
After using the blue serum, this serum disappears, and the power of the humanoid triples, so it increases by $3$ times.
The humanoid is wondering what the maximum number of astronauts he will be able to absorb if he acts optimally.
-----Input-----
The first line of each test contains an integer $t$ ($1 \le t \le 10^4$) β number of test cases.
The first line of each test case contains integers $n$ ($1 \le n \le 2 \cdot 10^5$) β number of astronauts and $h$ ($1 \le h \le 10^6$) β the initial power of the humanoid.
The second line of each test case contains $n$ integers $a_i$ ($1 \le a_i \le 10^8$) β powers of astronauts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, in a separate line, print the maximum number of astronauts that a humanoid can absorb.
-----Examples-----
Input
8
4 1
2 1 8 9
3 3
6 2 60
4 5
5 1 100 5
3 2
38 6 3
1 1
12
4 6
12 12 36 100
4 1
2 1 1 15
3 5
15 1 13
Output
4
3
3
3
0
4
4
3
-----Note-----
In the first case, you can proceed as follows:
use green serum. $h = 1 \cdot 2 = 2$
absorb the cosmonaut $2$. $h = 2 + \lfloor \frac{1}{2} \rfloor = 2$
use green serum. $h = 2 \cdot 2 = 4$
absorb the spaceman $1$. $h = 4 + \lfloor \frac{2}{2} \rfloor = 5$
use blue serum. $h = 5 \cdot 3 = 15$
absorb the spaceman $3$. $h = 15 + \lfloor \frac{8}{2} \rfloor = 19$
absorb the cosmonaut $4$. $h = 19 + \lfloor \frac{9}{2} \rfloor = 23$ | t = int(input())
def solve():
n, h = map(int, input().split())
arr = list(map(int, input().split()))
arr.sort()
x = h
score1 = 0
score2 = 0
score3 = 0
k = 0
i = 0
while i < n:
if arr[i] < h:
h += arr[i] // 2
score1 += 1
i += 1
elif k == 0:
h *= 2
k += 1
elif k == 1:
h *= 2
k += 1
elif k == 2:
h *= 3
k += 1
else:
break
i = 0
k = 0
h = x
while i < n:
if arr[i] < h:
h += arr[i] // 2
score2 += 1
i += 1
elif k == 0:
h *= 3
k += 1
elif k == 1:
h *= 2
k += 1
elif k == 2:
h *= 2
k += 1
else:
break
i = 0
k = 0
h = x
while i < n:
if arr[i] < h:
h += arr[i] // 2
score3 += 1
i += 1
elif k == 0:
h *= 2
k += 1
elif k == 1:
h *= 3
k += 1
elif k == 2:
h *= 2
k += 1
else:
break
print(max(score1, score2, score3))
while t:
solve()
t -= 1 | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF 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 EXPR FUNC_CALL VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR VAR WHILE VAR EXPR FUNC_CALL VAR VAR NUMBER |
There are $n$ astronauts working on some space station. An astronaut with the number $i$ ($1 \le i \le n$) has power $a_i$.
An evil humanoid has made his way to this space station. The power of this humanoid is equal to $h$. Also, the humanoid took with him two green serums and one blue serum.
In one second , a humanoid can do any of three actions:
to absorb an astronaut with power strictly less humanoid power;
to use green serum, if there is still one left;
to use blue serum, if there is still one left.
When an astronaut with power $a_i$ is absorbed, this astronaut disappears, and power of the humanoid increases by $\lfloor \frac{a_i}{2} \rfloor$, that is, an integer part of $\frac{a_i}{2}$. For example, if a humanoid absorbs an astronaut with power $4$, its power increases by $2$, and if a humanoid absorbs an astronaut with power $7$, its power increases by $3$.
After using the green serum, this serum disappears, and the power of the humanoid doubles, so it increases by $2$ times.
After using the blue serum, this serum disappears, and the power of the humanoid triples, so it increases by $3$ times.
The humanoid is wondering what the maximum number of astronauts he will be able to absorb if he acts optimally.
-----Input-----
The first line of each test contains an integer $t$ ($1 \le t \le 10^4$) β number of test cases.
The first line of each test case contains integers $n$ ($1 \le n \le 2 \cdot 10^5$) β number of astronauts and $h$ ($1 \le h \le 10^6$) β the initial power of the humanoid.
The second line of each test case contains $n$ integers $a_i$ ($1 \le a_i \le 10^8$) β powers of astronauts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, in a separate line, print the maximum number of astronauts that a humanoid can absorb.
-----Examples-----
Input
8
4 1
2 1 8 9
3 3
6 2 60
4 5
5 1 100 5
3 2
38 6 3
1 1
12
4 6
12 12 36 100
4 1
2 1 1 15
3 5
15 1 13
Output
4
3
3
3
0
4
4
3
-----Note-----
In the first case, you can proceed as follows:
use green serum. $h = 1 \cdot 2 = 2$
absorb the cosmonaut $2$. $h = 2 + \lfloor \frac{1}{2} \rfloor = 2$
use green serum. $h = 2 \cdot 2 = 4$
absorb the spaceman $1$. $h = 4 + \lfloor \frac{2}{2} \rfloor = 5$
use blue serum. $h = 5 \cdot 3 = 15$
absorb the spaceman $3$. $h = 15 + \lfloor \frac{8}{2} \rfloor = 19$
absorb the cosmonaut $4$. $h = 19 + \lfloor \frac{9}{2} \rfloor = 23$ | tests = int(input())
for test in range(tests):
pot = [[3, 2, 2], [2, 3, 2], [2, 2, 3]]
rangersCount, energy0 = map(int, input().split())
rangers0 = list(map(int, input().split()))
rangers0.sort()
ans = [0, 0, 0]
for i in pot:
rangers = rangers0
energy = energy0
potions = i
potion = 0
rangerIndex = 0
while rangerIndex < rangersCount:
ranger = rangers[rangerIndex]
if energy > ranger:
energy += int(ranger / 2)
rangerIndex += 1
else:
if potion == 3:
break
energy *= potions[potion]
potion += 1
ans.append(rangerIndex)
print(max(ans)) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER 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 EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER NUMBER NUMBER FOR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR VAR VAR IF VAR VAR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR |
There are $n$ astronauts working on some space station. An astronaut with the number $i$ ($1 \le i \le n$) has power $a_i$.
An evil humanoid has made his way to this space station. The power of this humanoid is equal to $h$. Also, the humanoid took with him two green serums and one blue serum.
In one second , a humanoid can do any of three actions:
to absorb an astronaut with power strictly less humanoid power;
to use green serum, if there is still one left;
to use blue serum, if there is still one left.
When an astronaut with power $a_i$ is absorbed, this astronaut disappears, and power of the humanoid increases by $\lfloor \frac{a_i}{2} \rfloor$, that is, an integer part of $\frac{a_i}{2}$. For example, if a humanoid absorbs an astronaut with power $4$, its power increases by $2$, and if a humanoid absorbs an astronaut with power $7$, its power increases by $3$.
After using the green serum, this serum disappears, and the power of the humanoid doubles, so it increases by $2$ times.
After using the blue serum, this serum disappears, and the power of the humanoid triples, so it increases by $3$ times.
The humanoid is wondering what the maximum number of astronauts he will be able to absorb if he acts optimally.
-----Input-----
The first line of each test contains an integer $t$ ($1 \le t \le 10^4$) β number of test cases.
The first line of each test case contains integers $n$ ($1 \le n \le 2 \cdot 10^5$) β number of astronauts and $h$ ($1 \le h \le 10^6$) β the initial power of the humanoid.
The second line of each test case contains $n$ integers $a_i$ ($1 \le a_i \le 10^8$) β powers of astronauts.
It is guaranteed that the sum of $n$ for all test cases does not exceed $2 \cdot 10^5$.
-----Output-----
For each test case, in a separate line, print the maximum number of astronauts that a humanoid can absorb.
-----Examples-----
Input
8
4 1
2 1 8 9
3 3
6 2 60
4 5
5 1 100 5
3 2
38 6 3
1 1
12
4 6
12 12 36 100
4 1
2 1 1 15
3 5
15 1 13
Output
4
3
3
3
0
4
4
3
-----Note-----
In the first case, you can proceed as follows:
use green serum. $h = 1 \cdot 2 = 2$
absorb the cosmonaut $2$. $h = 2 + \lfloor \frac{1}{2} \rfloor = 2$
use green serum. $h = 2 \cdot 2 = 4$
absorb the spaceman $1$. $h = 4 + \lfloor \frac{2}{2} \rfloor = 5$
use blue serum. $h = 5 \cdot 3 = 15$
absorb the spaceman $3$. $h = 15 + \lfloor \frac{8}{2} \rfloor = 19$
absorb the cosmonaut $4$. $h = 19 + \lfloor \frac{9}{2} \rfloor = 23$ | t = int(input())
for _ in range(t):
n, h0 = map(int, input().split())
L = list(map(int, input().split()))
L.sort()
res = 0
for ks in [[2, 2, 3], [2, 3, 2], [3, 2, 2]]:
i = 0
h = h0
x = 0
while i != n:
if L[i] < h:
h += L[i] // 2
i += 1
else:
if x == 3:
break
h *= ks[x]
x += 1
res = max(res, i)
print(res) | ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR 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 EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR LIST LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER LIST NUMBER NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER IF VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.