description
stringlengths 171
4k
| code
stringlengths 94
3.98k
| normalized_code
stringlengths 57
4.99k
|
|---|---|---|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: Choose one of the elements of the array (for example $a_i$) and increase it by $1$ (that is, replace it with $a_i + 1$).
You want to make the median of the array the largest possible using at most $k$ operations.
The median of the odd-sized array is the middle element after the array is sorted in non-decreasing order. For example, the median of the array $[1, 5, 2, 3, 5]$ is $3$.
-----Input-----
The first line contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5$, $n$ is odd, $1 \le k \le 10^9$)Β β the number of elements in the array and the largest number of operations you can make.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integerΒ β the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
In the third example, you can make four operations: increase first, fourth, sixth, seventh element. This way the array will be $[5, 1, 2, 5, 3, 5, 5]$ and the median will be $5$.
|
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
l = 1
r = 2000000000
def c(x):
ans = 0
for i in range(n // 2, n):
ans += max(0, x - a[i])
return ans
while l != r:
m = (l + r + 1) // 2
if c(m) <= k:
l = m
else:
r = m - 1
print(l)
|
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 NUMBER FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR RETURN VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: Choose one of the elements of the array (for example $a_i$) and increase it by $1$ (that is, replace it with $a_i + 1$).
You want to make the median of the array the largest possible using at most $k$ operations.
The median of the odd-sized array is the middle element after the array is sorted in non-decreasing order. For example, the median of the array $[1, 5, 2, 3, 5]$ is $3$.
-----Input-----
The first line contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5$, $n$ is odd, $1 \le k \le 10^9$)Β β the number of elements in the array and the largest number of operations you can make.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integerΒ β the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
In the third example, you can make four operations: increase first, fourth, sixth, seventh element. This way the array will be $[5, 1, 2, 5, 3, 5, 5]$ and the median will be $5$.
|
n, k = map(int, input().split())
a = list(map(int, input().split()))
a.sort()
j = 0
r = n // 2
cnt = 1
ans = 0
u = 0
for i in range(r + 1, n):
value = cnt * (a[i] - a[i - 1])
if value < k:
k -= value
elif value == k:
j = 1
ans = a[i]
break
else:
ans = a[i - 1] + k // cnt
u = 1
break
cnt += 1
if j != 1 and u != 1:
ans = a[n - 1] + k // (n - r)
if j == 1:
print(ans)
elif u == 1:
print(ans)
else:
print(ans)
|
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 NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR VAR VAR BIN_OP VAR NUMBER IF VAR VAR VAR VAR IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR VAR ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: Choose one of the elements of the array (for example $a_i$) and increase it by $1$ (that is, replace it with $a_i + 1$).
You want to make the median of the array the largest possible using at most $k$ operations.
The median of the odd-sized array is the middle element after the array is sorted in non-decreasing order. For example, the median of the array $[1, 5, 2, 3, 5]$ is $3$.
-----Input-----
The first line contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5$, $n$ is odd, $1 \le k \le 10^9$)Β β the number of elements in the array and the largest number of operations you can make.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integerΒ β the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
In the third example, you can make four operations: increase first, fourth, sixth, seventh element. This way the array will be $[5, 1, 2, 5, 3, 5, 5]$ and the median will be $5$.
|
n, k = list(map(int, input().split()))
arr = list(map(int, input().split()))
arr.sort()
arr = arr[n // 2 :]
mid = arr[0]
start = mid
end = mid + k
while start < end:
op = k
f = 0
med = (end + start + 1) // 2
for i in range(len(arr)):
if arr[i] < med:
op -= med - arr[i]
if op < 0:
f = 1
break
if f == 1:
end = med - 1
else:
start = med
print(start)
|
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 ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR VAR WHILE VAR VAR ASSIGN VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR BIN_OP VAR VAR VAR IF VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
You are given an array $a$ of $n$ integers, where $n$ is odd. You can make the following operation with it: Choose one of the elements of the array (for example $a_i$) and increase it by $1$ (that is, replace it with $a_i + 1$).
You want to make the median of the array the largest possible using at most $k$ operations.
The median of the odd-sized array is the middle element after the array is sorted in non-decreasing order. For example, the median of the array $[1, 5, 2, 3, 5]$ is $3$.
-----Input-----
The first line contains two integers $n$ and $k$ ($1 \le n \le 2 \cdot 10^5$, $n$ is odd, $1 \le k \le 10^9$)Β β the number of elements in the array and the largest number of operations you can make.
The second line contains $n$ integers $a_1, a_2, \ldots, a_n$ ($1 \le a_i \le 10^9$).
-----Output-----
Print a single integerΒ β the maximum possible median after the operations.
-----Examples-----
Input
3 2
1 3 5
Output
5
Input
5 5
1 2 1 1 1
Output
3
Input
7 7
4 1 2 4 3 4 4
Output
5
-----Note-----
In the first example, you can increase the second element twice. Than array will be $[1, 5, 5]$ and it's median is $5$.
In the second example, it is optimal to increase the second number and than increase third and fifth. This way the answer is $3$.
In the third example, you can make four operations: increase first, fourth, sixth, seventh element. This way the array will be $[5, 1, 2, 5, 3, 5, 5]$ and the median will be $5$.
|
def f(A, n, x, k):
c = 0
for i in range(n - 1, n // 2 - 1, -1):
if A[i] < x:
c = c + x - A[i]
if c > k:
return False
else:
return True
n, k = map(int, input().split())
a = input()
A = list(map(int, list(a.split())))
A.sort()
l = A[n // 2]
h = A[n // 2] + k
while l <= h:
mid = (l + h) // 2
if f(A, n, mid, k) == True and f(A, n, mid + 1, k) == False:
print(mid)
break
elif f(A, n, mid, k) == False:
h = mid - 1
elif f(A, n, mid + 1, k) == True:
l = mid + 1
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR VAR NUMBER FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER
|
There are n heaps of stone. The i-th heap has h_i stones. You want to change the number of stones in the heap by performing the following process once:
* You go through the heaps from the 3-rd heap to the n-th heap, in this order.
* Let i be the number of the current heap.
* You can choose a number d (0 β€ 3 β
d β€ h_i), move d stones from the i-th heap to the (i - 1)-th heap, and 2 β
d stones from the i-th heap to the (i - 2)-th heap.
* So after that h_i is decreased by 3 β
d, h_{i - 1} is increased by d, and h_{i - 2} is increased by 2 β
d.
* You can choose different or same d for different operations. Some heaps may become empty, but they still count as heaps.
What is the maximum number of stones in the smallest heap after the process?
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 β€ t β€ 2β
10^5). Description of the test cases follows.
The first line of each test case contains a single integer n (3 β€ n β€ 2 β
10^5).
The second lines of each test case contains n integers h_1, h_2, h_3, β¦, h_n (1 β€ h_i β€ 10^9).
It is guaranteed that the sum of n over all test cases does not exceed 2 β
10^5.
Output
For each test case, print the maximum number of stones that the smallest heap can contain.
Example
Input
4
4
1 2 10 100
4
100 100 100 1
5
5 1 1 1 8
6
1 2 3 4 5 6
Output
7
1
1
3
Note
In the first test case, the initial heap sizes are [1, 2, 10, 100]. We can move the stones as follows.
* move 3 stones and 6 from the 3-rd heap to the 2-nd and 1 heap respectively. The heap sizes will be [7, 5, 1, 100];
* move 6 stones and 12 stones from the last heap to the 3-rd and 2-nd heap respectively. The heap sizes will be [7, 17, 7, 82].
In the second test case, the last heap is 1, and we can not increase its size.
In the third test case, it is better not to move any stones.
In the last test case, the final achievable configuration of the heaps can be [3, 5, 3, 4, 3, 3].
|
import sys
def input():
return sys.stdin.readline()
def isGood(avail, mn, n):
s = [0] * n
for i in range(n - 1, -1, -1):
if i == 1:
break
if avail[i] + s[i] < mn:
return False
else:
s[i - 1] += min((avail[i] + s[i] - mn) // 3, avail[i] // 3)
s[i - 2] += min((avail[i] + s[i] - mn) // 3 * 2, avail[i] // 3 * 2)
if s[0] + avail[0] < mn or avail[1] + s[1] < mn:
return False
else:
return True
def binary_search(s, n):
l = 1
r = 1000000000
while l + 1 < r:
m = (l + r) // 2
if isGood(s, m, n):
l = m
else:
r = m
print(l)
for _ in range(int(input())):
n = int(input())
s = list(map(int, input().split()))
binary_search(s, n)
|
IMPORT FUNC_DEF RETURN FUNC_CALL VAR FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR NUMBER IF BIN_OP VAR VAR VAR VAR VAR RETURN NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR VAR VAR NUMBER NUMBER BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 heaps of stone. The i-th heap has h_i stones. You want to change the number of stones in the heap by performing the following process once:
* You go through the heaps from the 3-rd heap to the n-th heap, in this order.
* Let i be the number of the current heap.
* You can choose a number d (0 β€ 3 β
d β€ h_i), move d stones from the i-th heap to the (i - 1)-th heap, and 2 β
d stones from the i-th heap to the (i - 2)-th heap.
* So after that h_i is decreased by 3 β
d, h_{i - 1} is increased by d, and h_{i - 2} is increased by 2 β
d.
* You can choose different or same d for different operations. Some heaps may become empty, but they still count as heaps.
What is the maximum number of stones in the smallest heap after the process?
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 β€ t β€ 2β
10^5). Description of the test cases follows.
The first line of each test case contains a single integer n (3 β€ n β€ 2 β
10^5).
The second lines of each test case contains n integers h_1, h_2, h_3, β¦, h_n (1 β€ h_i β€ 10^9).
It is guaranteed that the sum of n over all test cases does not exceed 2 β
10^5.
Output
For each test case, print the maximum number of stones that the smallest heap can contain.
Example
Input
4
4
1 2 10 100
4
100 100 100 1
5
5 1 1 1 8
6
1 2 3 4 5 6
Output
7
1
1
3
Note
In the first test case, the initial heap sizes are [1, 2, 10, 100]. We can move the stones as follows.
* move 3 stones and 6 from the 3-rd heap to the 2-nd and 1 heap respectively. The heap sizes will be [7, 5, 1, 100];
* move 6 stones and 12 stones from the last heap to the 3-rd and 2-nd heap respectively. The heap sizes will be [7, 17, 7, 82].
In the second test case, the last heap is 1, and we can not increase its size.
In the third test case, it is better not to move any stones.
In the last test case, the final achievable configuration of the heaps can be [3, 5, 3, 4, 3, 3].
|
def verify(H, n, target):
d2, d1 = 0, 0
for i in range(2, n)[::-1]:
d2, d1, v = 0, d2, H[i] + d1
if v < target:
return False
d = min((v - target) // 3, H[i] // 3)
d2 += 2 * d
d1 += d
return H[0] + d2 >= target and H[1] + d1 >= target
for t in range(int(input())):
n = int(input())
H = tuple(int(v) for v in input().split())
lowerbound = min(H)
upperbound = min(sum(H) // n, H[-1])
for i in range(n - 2):
upperbound = min(upperbound, H[i] + H[i + 1] // 3 + H[i + 2] // 3 * 2)
upperbound = min(upperbound, H[-2] + H[-1] // 3)
upperbound += 1
while upperbound - lowerbound > 1:
mid = (upperbound + lowerbound) // 2
if verify(H, n, mid):
lowerbound = mid
else:
upperbound = mid
print(lowerbound)
|
FUNC_DEF ASSIGN VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER VAR BIN_OP VAR VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP NUMBER VAR VAR VAR RETURN BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR NUMBER NUMBER BIN_OP BIN_OP VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
There are n heaps of stone. The i-th heap has h_i stones. You want to change the number of stones in the heap by performing the following process once:
* You go through the heaps from the 3-rd heap to the n-th heap, in this order.
* Let i be the number of the current heap.
* You can choose a number d (0 β€ 3 β
d β€ h_i), move d stones from the i-th heap to the (i - 1)-th heap, and 2 β
d stones from the i-th heap to the (i - 2)-th heap.
* So after that h_i is decreased by 3 β
d, h_{i - 1} is increased by d, and h_{i - 2} is increased by 2 β
d.
* You can choose different or same d for different operations. Some heaps may become empty, but they still count as heaps.
What is the maximum number of stones in the smallest heap after the process?
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 β€ t β€ 2β
10^5). Description of the test cases follows.
The first line of each test case contains a single integer n (3 β€ n β€ 2 β
10^5).
The second lines of each test case contains n integers h_1, h_2, h_3, β¦, h_n (1 β€ h_i β€ 10^9).
It is guaranteed that the sum of n over all test cases does not exceed 2 β
10^5.
Output
For each test case, print the maximum number of stones that the smallest heap can contain.
Example
Input
4
4
1 2 10 100
4
100 100 100 1
5
5 1 1 1 8
6
1 2 3 4 5 6
Output
7
1
1
3
Note
In the first test case, the initial heap sizes are [1, 2, 10, 100]. We can move the stones as follows.
* move 3 stones and 6 from the 3-rd heap to the 2-nd and 1 heap respectively. The heap sizes will be [7, 5, 1, 100];
* move 6 stones and 12 stones from the last heap to the 3-rd and 2-nd heap respectively. The heap sizes will be [7, 17, 7, 82].
In the second test case, the last heap is 1, and we can not increase its size.
In the third test case, it is better not to move any stones.
In the last test case, the final achievable configuration of the heaps can be [3, 5, 3, 4, 3, 3].
|
def solve(arr, mini):
counter = [0, 0]
n = len(arr)
for i in range(n - 1, -1, -1):
if arr[i] + counter[0] + 2 * counter[1] - mini < 0:
return False
ext = arr[i] + counter[0] + 2 * counter[1] - mini
if counter[0] + 2 * counter[1] >= mini:
ext = arr[i]
counter[1] = counter[0]
counter[0] = ext // 3
if i == 1:
counter[0] = 0
return True
for _ in range(int(input())):
n = int(input())
arr = [int(i) for i in input().split()]
l = 0
r = 10**9 + 2
while l < r - 1:
mid = (l + r) // 2
if solve(arr, mid):
l = mid
else:
r = mid - 1
while not solve(arr, r):
r -= 1
print(r)
|
FUNC_DEF ASSIGN VAR LIST NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP NUMBER VAR NUMBER VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP NUMBER VAR NUMBER VAR IF BIN_OP VAR NUMBER BIN_OP NUMBER VAR NUMBER VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER ASSIGN VAR NUMBER NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 WHILE VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER WHILE FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are n heaps of stone. The i-th heap has h_i stones. You want to change the number of stones in the heap by performing the following process once:
* You go through the heaps from the 3-rd heap to the n-th heap, in this order.
* Let i be the number of the current heap.
* You can choose a number d (0 β€ 3 β
d β€ h_i), move d stones from the i-th heap to the (i - 1)-th heap, and 2 β
d stones from the i-th heap to the (i - 2)-th heap.
* So after that h_i is decreased by 3 β
d, h_{i - 1} is increased by d, and h_{i - 2} is increased by 2 β
d.
* You can choose different or same d for different operations. Some heaps may become empty, but they still count as heaps.
What is the maximum number of stones in the smallest heap after the process?
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 β€ t β€ 2β
10^5). Description of the test cases follows.
The first line of each test case contains a single integer n (3 β€ n β€ 2 β
10^5).
The second lines of each test case contains n integers h_1, h_2, h_3, β¦, h_n (1 β€ h_i β€ 10^9).
It is guaranteed that the sum of n over all test cases does not exceed 2 β
10^5.
Output
For each test case, print the maximum number of stones that the smallest heap can contain.
Example
Input
4
4
1 2 10 100
4
100 100 100 1
5
5 1 1 1 8
6
1 2 3 4 5 6
Output
7
1
1
3
Note
In the first test case, the initial heap sizes are [1, 2, 10, 100]. We can move the stones as follows.
* move 3 stones and 6 from the 3-rd heap to the 2-nd and 1 heap respectively. The heap sizes will be [7, 5, 1, 100];
* move 6 stones and 12 stones from the last heap to the 3-rd and 2-nd heap respectively. The heap sizes will be [7, 17, 7, 82].
In the second test case, the last heap is 1, and we can not increase its size.
In the third test case, it is better not to move any stones.
In the last test case, the final achievable configuration of the heaps can be [3, 5, 3, 4, 3, 3].
|
sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))
inf = 10**18
mod = 998244353
test = ir()
for t in range(test):
n = ir()
h = lr()
h.reverse()
def judge(x):
margin = [(0) for _ in range(n)]
for i in range(n - 2):
now_h = h[i]
m = margin[i]
d = min((now_h + m - x) // 3, now_h // 3)
if d < 0:
return False
margin[i + 1] += d
margin[i + 2] += 2 * d
if h[-2] + margin[-2] >= x and h[-1] + margin[-1] >= x:
return True
else:
return False
l = min(h)
r = max(h) + 1
while r - l > 1:
mid = l + (r - l) // 2
if judge(mid):
l = mid
else:
r = mid
print(l)
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 NUMBER ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR NUMBER VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP VAR NUMBER IF VAR NUMBER RETURN NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR IF BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
There are n heaps of stone. The i-th heap has h_i stones. You want to change the number of stones in the heap by performing the following process once:
* You go through the heaps from the 3-rd heap to the n-th heap, in this order.
* Let i be the number of the current heap.
* You can choose a number d (0 β€ 3 β
d β€ h_i), move d stones from the i-th heap to the (i - 1)-th heap, and 2 β
d stones from the i-th heap to the (i - 2)-th heap.
* So after that h_i is decreased by 3 β
d, h_{i - 1} is increased by d, and h_{i - 2} is increased by 2 β
d.
* You can choose different or same d for different operations. Some heaps may become empty, but they still count as heaps.
What is the maximum number of stones in the smallest heap after the process?
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 β€ t β€ 2β
10^5). Description of the test cases follows.
The first line of each test case contains a single integer n (3 β€ n β€ 2 β
10^5).
The second lines of each test case contains n integers h_1, h_2, h_3, β¦, h_n (1 β€ h_i β€ 10^9).
It is guaranteed that the sum of n over all test cases does not exceed 2 β
10^5.
Output
For each test case, print the maximum number of stones that the smallest heap can contain.
Example
Input
4
4
1 2 10 100
4
100 100 100 1
5
5 1 1 1 8
6
1 2 3 4 5 6
Output
7
1
1
3
Note
In the first test case, the initial heap sizes are [1, 2, 10, 100]. We can move the stones as follows.
* move 3 stones and 6 from the 3-rd heap to the 2-nd and 1 heap respectively. The heap sizes will be [7, 5, 1, 100];
* move 6 stones and 12 stones from the last heap to the 3-rd and 2-nd heap respectively. The heap sizes will be [7, 17, 7, 82].
In the second test case, the last heap is 1, and we can not increase its size.
In the third test case, it is better not to move any stones.
In the last test case, the final achievable configuration of the heaps can be [3, 5, 3, 4, 3, 3].
|
import sys
from sys import stdin
tt = int(stdin.readline())
ANS = []
for loop in range(tt):
n = int(stdin.readline())
h = list(map(int, stdin.readline().split()))
l = 0
r = max(h) + 1
while r - l != 1:
a = [i for i in h]
m = (l + r) // 2
for i in range(n - 1, -1, -1):
if a[i] < m:
r = m
break
if i >= 2:
rem = min(h[i], a[i] - m)
a[i - 1] += rem // 3
a[i - 2] += rem // 3 * 2
else:
l = m
ANS.append(str(l))
print("\n".join(ANS))
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL STRING VAR
|
There are n heaps of stone. The i-th heap has h_i stones. You want to change the number of stones in the heap by performing the following process once:
* You go through the heaps from the 3-rd heap to the n-th heap, in this order.
* Let i be the number of the current heap.
* You can choose a number d (0 β€ 3 β
d β€ h_i), move d stones from the i-th heap to the (i - 1)-th heap, and 2 β
d stones from the i-th heap to the (i - 2)-th heap.
* So after that h_i is decreased by 3 β
d, h_{i - 1} is increased by d, and h_{i - 2} is increased by 2 β
d.
* You can choose different or same d for different operations. Some heaps may become empty, but they still count as heaps.
What is the maximum number of stones in the smallest heap after the process?
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 β€ t β€ 2β
10^5). Description of the test cases follows.
The first line of each test case contains a single integer n (3 β€ n β€ 2 β
10^5).
The second lines of each test case contains n integers h_1, h_2, h_3, β¦, h_n (1 β€ h_i β€ 10^9).
It is guaranteed that the sum of n over all test cases does not exceed 2 β
10^5.
Output
For each test case, print the maximum number of stones that the smallest heap can contain.
Example
Input
4
4
1 2 10 100
4
100 100 100 1
5
5 1 1 1 8
6
1 2 3 4 5 6
Output
7
1
1
3
Note
In the first test case, the initial heap sizes are [1, 2, 10, 100]. We can move the stones as follows.
* move 3 stones and 6 from the 3-rd heap to the 2-nd and 1 heap respectively. The heap sizes will be [7, 5, 1, 100];
* move 6 stones and 12 stones from the last heap to the 3-rd and 2-nd heap respectively. The heap sizes will be [7, 17, 7, 82].
In the second test case, the last heap is 1, and we can not increase its size.
In the third test case, it is better not to move any stones.
In the last test case, the final achievable configuration of the heaps can be [3, 5, 3, 4, 3, 3].
|
T = int(input())
for t in range(T):
n = int(input())
A = [int(i) for i in input().split()]
lo = min(A)
hi = max(A)
def can(sz):
n = len(A)
Acp = A[:]
for i in range(n - 1, 1, -1):
if Acp[i] - A[i] > sz:
max_amt_donatable = A[i]
else:
max_amt_donatable = max(0, Acp[i] - sz)
d = max_amt_donatable // 3
if i - 1 >= 0:
Acp[i - 1] += d
if i - 2 >= 0:
Acp[i - 2] += 2 * d
Acp[i] -= 3 * d
for i in range(n):
if Acp[i] < sz:
return 0
return 1
while lo < hi:
mid = (lo + hi + 1) // 2
if can(mid):
lo = mid
else:
hi = mid - 1
print(lo)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF BIN_OP VAR VAR VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER VAR IF BIN_OP VAR NUMBER NUMBER VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR VAR BIN_OP NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR RETURN NUMBER RETURN NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are n heaps of stone. The i-th heap has h_i stones. You want to change the number of stones in the heap by performing the following process once:
* You go through the heaps from the 3-rd heap to the n-th heap, in this order.
* Let i be the number of the current heap.
* You can choose a number d (0 β€ 3 β
d β€ h_i), move d stones from the i-th heap to the (i - 1)-th heap, and 2 β
d stones from the i-th heap to the (i - 2)-th heap.
* So after that h_i is decreased by 3 β
d, h_{i - 1} is increased by d, and h_{i - 2} is increased by 2 β
d.
* You can choose different or same d for different operations. Some heaps may become empty, but they still count as heaps.
What is the maximum number of stones in the smallest heap after the process?
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 β€ t β€ 2β
10^5). Description of the test cases follows.
The first line of each test case contains a single integer n (3 β€ n β€ 2 β
10^5).
The second lines of each test case contains n integers h_1, h_2, h_3, β¦, h_n (1 β€ h_i β€ 10^9).
It is guaranteed that the sum of n over all test cases does not exceed 2 β
10^5.
Output
For each test case, print the maximum number of stones that the smallest heap can contain.
Example
Input
4
4
1 2 10 100
4
100 100 100 1
5
5 1 1 1 8
6
1 2 3 4 5 6
Output
7
1
1
3
Note
In the first test case, the initial heap sizes are [1, 2, 10, 100]. We can move the stones as follows.
* move 3 stones and 6 from the 3-rd heap to the 2-nd and 1 heap respectively. The heap sizes will be [7, 5, 1, 100];
* move 6 stones and 12 stones from the last heap to the 3-rd and 2-nd heap respectively. The heap sizes will be [7, 17, 7, 82].
In the second test case, the last heap is 1, and we can not increase its size.
In the third test case, it is better not to move any stones.
In the last test case, the final achievable configuration of the heaps can be [3, 5, 3, 4, 3, 3].
|
I = input
for _ in [0] * int(I()):
n, h, s, b = int(I()), [*map(int, I().split())], 1, 1 << 30
while b - s > 1:
m, u, i = (b + s) // 2, h[:], n
while i:
i -= 1
if u[i] < m:
b = m
break
x = [0, min(h[i], u[i] - m) // 3][i > 1]
u[i - 1] += x
u[i - 2] += 2 * x
else:
s = m
print(s)
|
ASSIGN VAR VAR FOR VAR BIN_OP LIST NUMBER FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER BIN_OP NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR VAR VAR BIN_OP BIN_OP VAR VAR NUMBER VAR VAR WHILE VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR LIST NUMBER BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
There are n heaps of stone. The i-th heap has h_i stones. You want to change the number of stones in the heap by performing the following process once:
* You go through the heaps from the 3-rd heap to the n-th heap, in this order.
* Let i be the number of the current heap.
* You can choose a number d (0 β€ 3 β
d β€ h_i), move d stones from the i-th heap to the (i - 1)-th heap, and 2 β
d stones from the i-th heap to the (i - 2)-th heap.
* So after that h_i is decreased by 3 β
d, h_{i - 1} is increased by d, and h_{i - 2} is increased by 2 β
d.
* You can choose different or same d for different operations. Some heaps may become empty, but they still count as heaps.
What is the maximum number of stones in the smallest heap after the process?
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 β€ t β€ 2β
10^5). Description of the test cases follows.
The first line of each test case contains a single integer n (3 β€ n β€ 2 β
10^5).
The second lines of each test case contains n integers h_1, h_2, h_3, β¦, h_n (1 β€ h_i β€ 10^9).
It is guaranteed that the sum of n over all test cases does not exceed 2 β
10^5.
Output
For each test case, print the maximum number of stones that the smallest heap can contain.
Example
Input
4
4
1 2 10 100
4
100 100 100 1
5
5 1 1 1 8
6
1 2 3 4 5 6
Output
7
1
1
3
Note
In the first test case, the initial heap sizes are [1, 2, 10, 100]. We can move the stones as follows.
* move 3 stones and 6 from the 3-rd heap to the 2-nd and 1 heap respectively. The heap sizes will be [7, 5, 1, 100];
* move 6 stones and 12 stones from the last heap to the 3-rd and 2-nd heap respectively. The heap sizes will be [7, 17, 7, 82].
In the second test case, the last heap is 1, and we can not increase its size.
In the third test case, it is better not to move any stones.
In the last test case, the final achievable configuration of the heaps can be [3, 5, 3, 4, 3, 3].
|
def solve(n, k, a):
ex = [(0) for i in a]
for i in range(n - 1, 1, -1):
s = a[i] + ex[i]
if s < k:
return False
sh = a[i] - max(k - ex[i], 0)
ex[i - 1] += sh // 3
ex[i - 2] += 2 * (sh // 3)
return a[0] + ex[0] >= k and a[1] + ex[1] >= k
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
l = min(a)
r = max(a)
ans = l
while r >= l:
m = l + (r - l) // 2
if solve(n, m, a):
ans = max(ans, m)
l = m + 1
else:
r = m - 1
print(ans)
|
FUNC_DEF ASSIGN VAR NUMBER VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR BIN_OP VAR VAR VAR VAR IF VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP NUMBER BIN_OP VAR NUMBER RETURN BIN_OP VAR NUMBER VAR NUMBER VAR BIN_OP VAR NUMBER VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR 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 FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are n heaps of stone. The i-th heap has h_i stones. You want to change the number of stones in the heap by performing the following process once:
* You go through the heaps from the 3-rd heap to the n-th heap, in this order.
* Let i be the number of the current heap.
* You can choose a number d (0 β€ 3 β
d β€ h_i), move d stones from the i-th heap to the (i - 1)-th heap, and 2 β
d stones from the i-th heap to the (i - 2)-th heap.
* So after that h_i is decreased by 3 β
d, h_{i - 1} is increased by d, and h_{i - 2} is increased by 2 β
d.
* You can choose different or same d for different operations. Some heaps may become empty, but they still count as heaps.
What is the maximum number of stones in the smallest heap after the process?
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 β€ t β€ 2β
10^5). Description of the test cases follows.
The first line of each test case contains a single integer n (3 β€ n β€ 2 β
10^5).
The second lines of each test case contains n integers h_1, h_2, h_3, β¦, h_n (1 β€ h_i β€ 10^9).
It is guaranteed that the sum of n over all test cases does not exceed 2 β
10^5.
Output
For each test case, print the maximum number of stones that the smallest heap can contain.
Example
Input
4
4
1 2 10 100
4
100 100 100 1
5
5 1 1 1 8
6
1 2 3 4 5 6
Output
7
1
1
3
Note
In the first test case, the initial heap sizes are [1, 2, 10, 100]. We can move the stones as follows.
* move 3 stones and 6 from the 3-rd heap to the 2-nd and 1 heap respectively. The heap sizes will be [7, 5, 1, 100];
* move 6 stones and 12 stones from the last heap to the 3-rd and 2-nd heap respectively. The heap sizes will be [7, 17, 7, 82].
In the second test case, the last heap is 1, and we can not increase its size.
In the third test case, it is better not to move any stones.
In the last test case, the final achievable configuration of the heaps can be [3, 5, 3, 4, 3, 3].
|
import sys
I = lambda: [*map(int, sys.stdin.readline().split())]
(t,) = I()
for _ in range(t):
(n,) = I()
h = I()
sml = 1
big = 10**9 + 1
while big - sml > 1:
mid = (big + sml) // 2
use = [0] * n
for i in range(n - 1, -1, -1):
curr = h[i]
if i + 1 < n:
curr += use[i + 1]
if i + 2 < n:
curr += 2 * use[i + 2]
if curr < mid:
big = mid
break
if i > 1:
use[i] = min(h[i], curr - mid) // 3
else:
sml = mid
print(sml)
|
IMPORT ASSIGN VAR LIST FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR VAR VAR IF BIN_OP VAR NUMBER VAR VAR VAR BIN_OP VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR BIN_OP NUMBER VAR BIN_OP VAR NUMBER IF VAR VAR ASSIGN VAR VAR IF VAR NUMBER ASSIGN VAR VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
There are n heaps of stone. The i-th heap has h_i stones. You want to change the number of stones in the heap by performing the following process once:
* You go through the heaps from the 3-rd heap to the n-th heap, in this order.
* Let i be the number of the current heap.
* You can choose a number d (0 β€ 3 β
d β€ h_i), move d stones from the i-th heap to the (i - 1)-th heap, and 2 β
d stones from the i-th heap to the (i - 2)-th heap.
* So after that h_i is decreased by 3 β
d, h_{i - 1} is increased by d, and h_{i - 2} is increased by 2 β
d.
* You can choose different or same d for different operations. Some heaps may become empty, but they still count as heaps.
What is the maximum number of stones in the smallest heap after the process?
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 β€ t β€ 2β
10^5). Description of the test cases follows.
The first line of each test case contains a single integer n (3 β€ n β€ 2 β
10^5).
The second lines of each test case contains n integers h_1, h_2, h_3, β¦, h_n (1 β€ h_i β€ 10^9).
It is guaranteed that the sum of n over all test cases does not exceed 2 β
10^5.
Output
For each test case, print the maximum number of stones that the smallest heap can contain.
Example
Input
4
4
1 2 10 100
4
100 100 100 1
5
5 1 1 1 8
6
1 2 3 4 5 6
Output
7
1
1
3
Note
In the first test case, the initial heap sizes are [1, 2, 10, 100]. We can move the stones as follows.
* move 3 stones and 6 from the 3-rd heap to the 2-nd and 1 heap respectively. The heap sizes will be [7, 5, 1, 100];
* move 6 stones and 12 stones from the last heap to the 3-rd and 2-nd heap respectively. The heap sizes will be [7, 17, 7, 82].
In the second test case, the last heap is 1, and we can not increase its size.
In the third test case, it is better not to move any stones.
In the last test case, the final achievable configuration of the heaps can be [3, 5, 3, 4, 3, 3].
|
def check(a, m):
tmp = a.copy()
for i in range(n - 1, 1, -1):
if tmp[i] < m:
return False
d = (tmp[i] - m) // 3
if 3 * d > a[i]:
d = a[i] // 3
tmp[i - 1] += d
tmp[i - 2] += 2 * d
if tmp[0] < m or tmp[1] < m:
return False
return True
t = int(input())
for _ in range(t):
n = int(input())
a = list(map(int, input().split()))
l, r = min(a), max(a) + 1
while r - l > 1:
m = (l + r) // 2
if check(a, m):
l = m
else:
r = m
print(l)
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER IF BIN_OP NUMBER VAR VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR IF VAR NUMBER VAR VAR NUMBER VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP FUNC_CALL VAR VAR NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
There are n heaps of stone. The i-th heap has h_i stones. You want to change the number of stones in the heap by performing the following process once:
* You go through the heaps from the 3-rd heap to the n-th heap, in this order.
* Let i be the number of the current heap.
* You can choose a number d (0 β€ 3 β
d β€ h_i), move d stones from the i-th heap to the (i - 1)-th heap, and 2 β
d stones from the i-th heap to the (i - 2)-th heap.
* So after that h_i is decreased by 3 β
d, h_{i - 1} is increased by d, and h_{i - 2} is increased by 2 β
d.
* You can choose different or same d for different operations. Some heaps may become empty, but they still count as heaps.
What is the maximum number of stones in the smallest heap after the process?
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 β€ t β€ 2β
10^5). Description of the test cases follows.
The first line of each test case contains a single integer n (3 β€ n β€ 2 β
10^5).
The second lines of each test case contains n integers h_1, h_2, h_3, β¦, h_n (1 β€ h_i β€ 10^9).
It is guaranteed that the sum of n over all test cases does not exceed 2 β
10^5.
Output
For each test case, print the maximum number of stones that the smallest heap can contain.
Example
Input
4
4
1 2 10 100
4
100 100 100 1
5
5 1 1 1 8
6
1 2 3 4 5 6
Output
7
1
1
3
Note
In the first test case, the initial heap sizes are [1, 2, 10, 100]. We can move the stones as follows.
* move 3 stones and 6 from the 3-rd heap to the 2-nd and 1 heap respectively. The heap sizes will be [7, 5, 1, 100];
* move 6 stones and 12 stones from the last heap to the 3-rd and 2-nd heap respectively. The heap sizes will be [7, 17, 7, 82].
In the second test case, the last heap is 1, and we can not increase its size.
In the third test case, it is better not to move any stones.
In the last test case, the final achievable configuration of the heaps can be [3, 5, 3, 4, 3, 3].
|
def valid(heap, val):
new_heap = [i for i in heap]
for i in reversed(range(2, len(heap))):
thing = max(min(heap[i] // 3, (new_heap[i] - val) // 3), 0)
new_heap[i] -= 3 * thing
new_heap[i - 1] += thing
new_heap[i - 2] += 2 * thing
for i in new_heap:
if i < val:
return False
return True
for _ in range(int(input())):
input()
heap = list(map(int, input().split()))
start, end = 0, max(heap) + 1
while start < end:
mid = (start + end) // 2
if mid == start or mid == end:
break
if valid(heap, mid):
start = mid
else:
end = mid
print(start)
|
FUNC_DEF ASSIGN VAR VAR VAR VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER NUMBER VAR VAR BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR FOR VAR VAR IF VAR VAR RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP FUNC_CALL VAR VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF VAR VAR VAR VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
There are n heaps of stone. The i-th heap has h_i stones. You want to change the number of stones in the heap by performing the following process once:
* You go through the heaps from the 3-rd heap to the n-th heap, in this order.
* Let i be the number of the current heap.
* You can choose a number d (0 β€ 3 β
d β€ h_i), move d stones from the i-th heap to the (i - 1)-th heap, and 2 β
d stones from the i-th heap to the (i - 2)-th heap.
* So after that h_i is decreased by 3 β
d, h_{i - 1} is increased by d, and h_{i - 2} is increased by 2 β
d.
* You can choose different or same d for different operations. Some heaps may become empty, but they still count as heaps.
What is the maximum number of stones in the smallest heap after the process?
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 β€ t β€ 2β
10^5). Description of the test cases follows.
The first line of each test case contains a single integer n (3 β€ n β€ 2 β
10^5).
The second lines of each test case contains n integers h_1, h_2, h_3, β¦, h_n (1 β€ h_i β€ 10^9).
It is guaranteed that the sum of n over all test cases does not exceed 2 β
10^5.
Output
For each test case, print the maximum number of stones that the smallest heap can contain.
Example
Input
4
4
1 2 10 100
4
100 100 100 1
5
5 1 1 1 8
6
1 2 3 4 5 6
Output
7
1
1
3
Note
In the first test case, the initial heap sizes are [1, 2, 10, 100]. We can move the stones as follows.
* move 3 stones and 6 from the 3-rd heap to the 2-nd and 1 heap respectively. The heap sizes will be [7, 5, 1, 100];
* move 6 stones and 12 stones from the last heap to the 3-rd and 2-nd heap respectively. The heap sizes will be [7, 17, 7, 82].
In the second test case, the last heap is 1, and we can not increase its size.
In the third test case, it is better not to move any stones.
In the last test case, the final achievable configuration of the heaps can be [3, 5, 3, 4, 3, 3].
|
t = int(input())
for _ in range(t):
n = int(input())
stones = list(map(int, input().split()))
l, r = 0, 10**9 + 1
while abs(r - l) > 1:
tmp = [0] * n
tmp[0] = stones[0]
tmp[1] = stones[1]
mid = (l + r) // 2
for i in range(n - 1, 1, -1):
tmp[i] += stones[i]
d = max(0, min((tmp[i] - mid) // 3, stones[i] // 3))
tmp[i - 1] += d
tmp[i - 2] += 2 * d
tmp[i] -= 3 * d
if min(tmp) < mid:
r = mid
else:
l = mid
print(l)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR VAR NUMBER BIN_OP BIN_OP NUMBER NUMBER NUMBER WHILE FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER VAR VAR VAR VAR ASSIGN VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR BIN_OP BIN_OP VAR VAR VAR NUMBER BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR VAR BIN_OP NUMBER VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
There are n heaps of stone. The i-th heap has h_i stones. You want to change the number of stones in the heap by performing the following process once:
* You go through the heaps from the 3-rd heap to the n-th heap, in this order.
* Let i be the number of the current heap.
* You can choose a number d (0 β€ 3 β
d β€ h_i), move d stones from the i-th heap to the (i - 1)-th heap, and 2 β
d stones from the i-th heap to the (i - 2)-th heap.
* So after that h_i is decreased by 3 β
d, h_{i - 1} is increased by d, and h_{i - 2} is increased by 2 β
d.
* You can choose different or same d for different operations. Some heaps may become empty, but they still count as heaps.
What is the maximum number of stones in the smallest heap after the process?
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 β€ t β€ 2β
10^5). Description of the test cases follows.
The first line of each test case contains a single integer n (3 β€ n β€ 2 β
10^5).
The second lines of each test case contains n integers h_1, h_2, h_3, β¦, h_n (1 β€ h_i β€ 10^9).
It is guaranteed that the sum of n over all test cases does not exceed 2 β
10^5.
Output
For each test case, print the maximum number of stones that the smallest heap can contain.
Example
Input
4
4
1 2 10 100
4
100 100 100 1
5
5 1 1 1 8
6
1 2 3 4 5 6
Output
7
1
1
3
Note
In the first test case, the initial heap sizes are [1, 2, 10, 100]. We can move the stones as follows.
* move 3 stones and 6 from the 3-rd heap to the 2-nd and 1 heap respectively. The heap sizes will be [7, 5, 1, 100];
* move 6 stones and 12 stones from the last heap to the 3-rd and 2-nd heap respectively. The heap sizes will be [7, 17, 7, 82].
In the second test case, the last heap is 1, and we can not increase its size.
In the third test case, it is better not to move any stones.
In the last test case, the final achievable configuration of the heaps can be [3, 5, 3, 4, 3, 3].
|
for i in range(int(input())):
n = int(input())
h = list(map(int, input().split()))
l = 0
r = 10**9
while l < r:
a = h.copy()
mid = (l + r + 1) // 2
for i in range(n - 1, 1, -1):
if a[i] < mid:
break
d = min(h[i], a[i] - mid) // 3
a[i] -= 3 * d
a[i - 1] += d
a[i - 2] += 2 * d
if min(a) >= mid:
l = mid
else:
r = mid - 1
print(l)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR VAR BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are n heaps of stone. The i-th heap has h_i stones. You want to change the number of stones in the heap by performing the following process once:
* You go through the heaps from the 3-rd heap to the n-th heap, in this order.
* Let i be the number of the current heap.
* You can choose a number d (0 β€ 3 β
d β€ h_i), move d stones from the i-th heap to the (i - 1)-th heap, and 2 β
d stones from the i-th heap to the (i - 2)-th heap.
* So after that h_i is decreased by 3 β
d, h_{i - 1} is increased by d, and h_{i - 2} is increased by 2 β
d.
* You can choose different or same d for different operations. Some heaps may become empty, but they still count as heaps.
What is the maximum number of stones in the smallest heap after the process?
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 β€ t β€ 2β
10^5). Description of the test cases follows.
The first line of each test case contains a single integer n (3 β€ n β€ 2 β
10^5).
The second lines of each test case contains n integers h_1, h_2, h_3, β¦, h_n (1 β€ h_i β€ 10^9).
It is guaranteed that the sum of n over all test cases does not exceed 2 β
10^5.
Output
For each test case, print the maximum number of stones that the smallest heap can contain.
Example
Input
4
4
1 2 10 100
4
100 100 100 1
5
5 1 1 1 8
6
1 2 3 4 5 6
Output
7
1
1
3
Note
In the first test case, the initial heap sizes are [1, 2, 10, 100]. We can move the stones as follows.
* move 3 stones and 6 from the 3-rd heap to the 2-nd and 1 heap respectively. The heap sizes will be [7, 5, 1, 100];
* move 6 stones and 12 stones from the last heap to the 3-rd and 2-nd heap respectively. The heap sizes will be [7, 17, 7, 82].
In the second test case, the last heap is 1, and we can not increase its size.
In the third test case, it is better not to move any stones.
In the last test case, the final achievable configuration of the heaps can be [3, 5, 3, 4, 3, 3].
|
for _ in range(int(input())):
n = int(input())
h = list(map(int, input().split()))
l = 0
r = 10**9 + 10
while r - l > 1:
m = (l + r) // 2
k = h.copy()
flag = True
for i in range(n - 1, 1, -1):
if k[i] < m:
flag = False
break
d = (k[i] - m) // 3
if d * 3 > h[i]:
d = h[i] // 3
k[i - 1] += d
k[i - 2] += 2 * d
if k[0] < m or k[1] < m:
flag = False
if flag:
l = m
else:
r = m
print(l)
|
FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER WHILE BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER IF BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR IF VAR NUMBER VAR VAR NUMBER VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
There are n heaps of stone. The i-th heap has h_i stones. You want to change the number of stones in the heap by performing the following process once:
* You go through the heaps from the 3-rd heap to the n-th heap, in this order.
* Let i be the number of the current heap.
* You can choose a number d (0 β€ 3 β
d β€ h_i), move d stones from the i-th heap to the (i - 1)-th heap, and 2 β
d stones from the i-th heap to the (i - 2)-th heap.
* So after that h_i is decreased by 3 β
d, h_{i - 1} is increased by d, and h_{i - 2} is increased by 2 β
d.
* You can choose different or same d for different operations. Some heaps may become empty, but they still count as heaps.
What is the maximum number of stones in the smallest heap after the process?
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 β€ t β€ 2β
10^5). Description of the test cases follows.
The first line of each test case contains a single integer n (3 β€ n β€ 2 β
10^5).
The second lines of each test case contains n integers h_1, h_2, h_3, β¦, h_n (1 β€ h_i β€ 10^9).
It is guaranteed that the sum of n over all test cases does not exceed 2 β
10^5.
Output
For each test case, print the maximum number of stones that the smallest heap can contain.
Example
Input
4
4
1 2 10 100
4
100 100 100 1
5
5 1 1 1 8
6
1 2 3 4 5 6
Output
7
1
1
3
Note
In the first test case, the initial heap sizes are [1, 2, 10, 100]. We can move the stones as follows.
* move 3 stones and 6 from the 3-rd heap to the 2-nd and 1 heap respectively. The heap sizes will be [7, 5, 1, 100];
* move 6 stones and 12 stones from the last heap to the 3-rd and 2-nd heap respectively. The heap sizes will be [7, 17, 7, 82].
In the second test case, the last heap is 1, and we can not increase its size.
In the third test case, it is better not to move any stones.
In the last test case, the final achievable configuration of the heaps can be [3, 5, 3, 4, 3, 3].
|
import sys
input = sys.stdin.readline
def inp():
return int(input())
def st():
return input().rstrip("\n")
def lis():
return list(map(int, input().split()))
def ma():
return map(int, input().split())
def possible(k, a):
b = a[:]
n = len(a)
extrasum = [0] * n
for i in range(n - 1, 1, -1):
get = min(b[i], b[i] + extrasum[i] - k)
if get < 0:
return 0
qu = get // 3
b[i] -= 3 * qu
extrasum[i - 1] += qu
extrasum[i - 2] += qu * 2
for i in range(n):
if extrasum[i] + b[i] < k:
return 0
return 1
t = inp()
while t:
t -= 1
n = inp()
a = lis()
l = 1
r = a[-1]
r += 2
ans = 0
while l <= r:
mid = (l + r) // 2
if possible(mid, a):
l = mid + 1
ans = max(ans, mid)
else:
r = mid - 1
print(ans)
|
IMPORT ASSIGN VAR VAR FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP LIST NUMBER VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR BIN_OP BIN_OP VAR VAR VAR VAR VAR IF VAR NUMBER RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER VAR VAR BIN_OP NUMBER VAR VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR 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 heaps of stone. The i-th heap has h_i stones. You want to change the number of stones in the heap by performing the following process once:
* You go through the heaps from the 3-rd heap to the n-th heap, in this order.
* Let i be the number of the current heap.
* You can choose a number d (0 β€ 3 β
d β€ h_i), move d stones from the i-th heap to the (i - 1)-th heap, and 2 β
d stones from the i-th heap to the (i - 2)-th heap.
* So after that h_i is decreased by 3 β
d, h_{i - 1} is increased by d, and h_{i - 2} is increased by 2 β
d.
* You can choose different or same d for different operations. Some heaps may become empty, but they still count as heaps.
What is the maximum number of stones in the smallest heap after the process?
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 β€ t β€ 2β
10^5). Description of the test cases follows.
The first line of each test case contains a single integer n (3 β€ n β€ 2 β
10^5).
The second lines of each test case contains n integers h_1, h_2, h_3, β¦, h_n (1 β€ h_i β€ 10^9).
It is guaranteed that the sum of n over all test cases does not exceed 2 β
10^5.
Output
For each test case, print the maximum number of stones that the smallest heap can contain.
Example
Input
4
4
1 2 10 100
4
100 100 100 1
5
5 1 1 1 8
6
1 2 3 4 5 6
Output
7
1
1
3
Note
In the first test case, the initial heap sizes are [1, 2, 10, 100]. We can move the stones as follows.
* move 3 stones and 6 from the 3-rd heap to the 2-nd and 1 heap respectively. The heap sizes will be [7, 5, 1, 100];
* move 6 stones and 12 stones from the last heap to the 3-rd and 2-nd heap respectively. The heap sizes will be [7, 17, 7, 82].
In the second test case, the last heap is 1, and we can not increase its size.
In the third test case, it is better not to move any stones.
In the last test case, the final achievable configuration of the heaps can be [3, 5, 3, 4, 3, 3].
|
def check(mid, arr, n):
v = arr.copy()
for i in range(n - 1, 1, -1):
if v[i] < mid:
return False
x = min(arr[i], v[i] - mid) // 3
v[i - 1] += x
v[i - 2] += x * 2
return v[0] >= mid and v[1] >= mid
def solve():
for _ in range(int(input())):
n = int(input())
arr = list(map(int, input().split()))
l = 0
r = max(arr)
while l < r:
mid = int(l + (r - l + 1) / 2)
if check(mid, arr, n):
l = mid
else:
r = mid - 1
print(l)
solve()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR RETURN NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER RETURN VAR NUMBER VAR VAR NUMBER VAR FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER IF FUNC_CALL VAR VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
There are n heaps of stone. The i-th heap has h_i stones. You want to change the number of stones in the heap by performing the following process once:
* You go through the heaps from the 3-rd heap to the n-th heap, in this order.
* Let i be the number of the current heap.
* You can choose a number d (0 β€ 3 β
d β€ h_i), move d stones from the i-th heap to the (i - 1)-th heap, and 2 β
d stones from the i-th heap to the (i - 2)-th heap.
* So after that h_i is decreased by 3 β
d, h_{i - 1} is increased by d, and h_{i - 2} is increased by 2 β
d.
* You can choose different or same d for different operations. Some heaps may become empty, but they still count as heaps.
What is the maximum number of stones in the smallest heap after the process?
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 β€ t β€ 2β
10^5). Description of the test cases follows.
The first line of each test case contains a single integer n (3 β€ n β€ 2 β
10^5).
The second lines of each test case contains n integers h_1, h_2, h_3, β¦, h_n (1 β€ h_i β€ 10^9).
It is guaranteed that the sum of n over all test cases does not exceed 2 β
10^5.
Output
For each test case, print the maximum number of stones that the smallest heap can contain.
Example
Input
4
4
1 2 10 100
4
100 100 100 1
5
5 1 1 1 8
6
1 2 3 4 5 6
Output
7
1
1
3
Note
In the first test case, the initial heap sizes are [1, 2, 10, 100]. We can move the stones as follows.
* move 3 stones and 6 from the 3-rd heap to the 2-nd and 1 heap respectively. The heap sizes will be [7, 5, 1, 100];
* move 6 stones and 12 stones from the last heap to the 3-rd and 2-nd heap respectively. The heap sizes will be [7, 17, 7, 82].
In the second test case, the last heap is 1, and we can not increase its size.
In the third test case, it is better not to move any stones.
In the last test case, the final achievable configuration of the heaps can be [3, 5, 3, 4, 3, 3].
|
def read_ints():
return [int(x) for x in input().rstrip().rsplit()]
def ok(arr, k):
test_arr = arr.copy()
for i in range(len(arr) - 1, 1, -1):
if test_arr[i] < k:
return False
d_i = min(test_arr[i] - k, arr[i])
test_arr[i - 1] += d_i // 3
test_arr[i - 2] += d_i // 3 * 2
return test_arr[0] >= k and test_arr[1] >= k
def binarySearch(arr) -> int:
bad = 1000000000
good = 0
while abs(bad - good) > 1:
middle = (bad + good) // 2
if ok(arr, middle):
good = middle
else:
bad = middle
return good
nn = int(input())
while nn > 0:
n = int(input())
arr = read_ints()
print(binarySearch(arr))
nn -= 1
|
FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER NUMBER RETURN VAR NUMBER VAR VAR NUMBER VAR FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE FUNC_CALL VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR WHILE VAR NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR VAR NUMBER
|
There are n heaps of stone. The i-th heap has h_i stones. You want to change the number of stones in the heap by performing the following process once:
* You go through the heaps from the 3-rd heap to the n-th heap, in this order.
* Let i be the number of the current heap.
* You can choose a number d (0 β€ 3 β
d β€ h_i), move d stones from the i-th heap to the (i - 1)-th heap, and 2 β
d stones from the i-th heap to the (i - 2)-th heap.
* So after that h_i is decreased by 3 β
d, h_{i - 1} is increased by d, and h_{i - 2} is increased by 2 β
d.
* You can choose different or same d for different operations. Some heaps may become empty, but they still count as heaps.
What is the maximum number of stones in the smallest heap after the process?
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 β€ t β€ 2β
10^5). Description of the test cases follows.
The first line of each test case contains a single integer n (3 β€ n β€ 2 β
10^5).
The second lines of each test case contains n integers h_1, h_2, h_3, β¦, h_n (1 β€ h_i β€ 10^9).
It is guaranteed that the sum of n over all test cases does not exceed 2 β
10^5.
Output
For each test case, print the maximum number of stones that the smallest heap can contain.
Example
Input
4
4
1 2 10 100
4
100 100 100 1
5
5 1 1 1 8
6
1 2 3 4 5 6
Output
7
1
1
3
Note
In the first test case, the initial heap sizes are [1, 2, 10, 100]. We can move the stones as follows.
* move 3 stones and 6 from the 3-rd heap to the 2-nd and 1 heap respectively. The heap sizes will be [7, 5, 1, 100];
* move 6 stones and 12 stones from the last heap to the 3-rd and 2-nd heap respectively. The heap sizes will be [7, 17, 7, 82].
In the second test case, the last heap is 1, and we can not increase its size.
In the third test case, it is better not to move any stones.
In the last test case, the final achievable configuration of the heaps can be [3, 5, 3, 4, 3, 3].
|
import sys
T = int(sys.stdin.readline().strip())
for t in range(0, T):
n = int(sys.stdin.readline().strip())
h = list(map(int, sys.stdin.readline().strip().split()))
m = min(h)
M = max(h)
while m < M:
x = (m + M + 1) // 2
h1 = h[:]
for i in range(2, n):
if h1[n + 1 - i] < x:
break
else:
d = min(h1[n + 1 - i] - x, h[n + 1 - i]) // 3
h1[n + 1 - i] = h1[n + 1 - i] - 3 * d
h1[n - i] = h1[n - i] + d
h1[n - 1 - i] = h1[n - 1 - i] + 2 * d
if min(h1) < x:
M = x - 1
else:
m = x
print(m)
|
IMPORT ASSIGN VAR FUNC_CALL VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR 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 VAR ASSIGN VAR FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER NUMBER ASSIGN VAR VAR FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR BIN_OP BIN_OP VAR NUMBER VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR VAR VAR BIN_OP BIN_OP VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP NUMBER VAR ASSIGN VAR BIN_OP VAR VAR BIN_OP VAR BIN_OP VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP VAR BIN_OP BIN_OP VAR NUMBER VAR BIN_OP NUMBER VAR IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
There are n heaps of stone. The i-th heap has h_i stones. You want to change the number of stones in the heap by performing the following process once:
* You go through the heaps from the 3-rd heap to the n-th heap, in this order.
* Let i be the number of the current heap.
* You can choose a number d (0 β€ 3 β
d β€ h_i), move d stones from the i-th heap to the (i - 1)-th heap, and 2 β
d stones from the i-th heap to the (i - 2)-th heap.
* So after that h_i is decreased by 3 β
d, h_{i - 1} is increased by d, and h_{i - 2} is increased by 2 β
d.
* You can choose different or same d for different operations. Some heaps may become empty, but they still count as heaps.
What is the maximum number of stones in the smallest heap after the process?
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 β€ t β€ 2β
10^5). Description of the test cases follows.
The first line of each test case contains a single integer n (3 β€ n β€ 2 β
10^5).
The second lines of each test case contains n integers h_1, h_2, h_3, β¦, h_n (1 β€ h_i β€ 10^9).
It is guaranteed that the sum of n over all test cases does not exceed 2 β
10^5.
Output
For each test case, print the maximum number of stones that the smallest heap can contain.
Example
Input
4
4
1 2 10 100
4
100 100 100 1
5
5 1 1 1 8
6
1 2 3 4 5 6
Output
7
1
1
3
Note
In the first test case, the initial heap sizes are [1, 2, 10, 100]. We can move the stones as follows.
* move 3 stones and 6 from the 3-rd heap to the 2-nd and 1 heap respectively. The heap sizes will be [7, 5, 1, 100];
* move 6 stones and 12 stones from the last heap to the 3-rd and 2-nd heap respectively. The heap sizes will be [7, 17, 7, 82].
In the second test case, the last heap is 1, and we can not increase its size.
In the third test case, it is better not to move any stones.
In the last test case, the final achievable configuration of the heaps can be [3, 5, 3, 4, 3, 3].
|
from sys import stdin
input = stdin.readline
rn = lambda: int(input())
rns = lambda: map(int, input().split())
rl = lambda: list(map(int, input().split()))
rs = lambda: input().strip()
YN = lambda x: print("YES") if x else print("NO")
ceil_div = lambda a, b: -(-a // b)
mod = 10**9 + 7
for _ in range(rn()):
n = rn()
h = rl()
lo = min(h)
hi = max(h)
ans = lo
def f(val, arr):
for i in range(len(arr) - 1, 1, -1):
if arr[i] < val:
return False
diff = min(arr[i] - val, h[i])
diff -= diff % 3
arr[i] -= diff
arr[i - 1] += diff // 3
arr[i - 2] += 2 * diff // 3
return arr[0] >= val and arr[1] >= val
while lo <= hi:
mid = (lo + hi) // 2
if f(mid, h.copy()):
ans = max(ans, mid)
lo = mid + 1
else:
hi = mid - 1
print(ans)
|
ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN 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 FUNC_CALL VAR ASSIGN VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR STRING ASSIGN VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR FUNC_DEF FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF VAR VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR VAR BIN_OP VAR NUMBER VAR VAR VAR VAR BIN_OP VAR NUMBER BIN_OP VAR NUMBER VAR BIN_OP VAR NUMBER BIN_OP BIN_OP NUMBER VAR NUMBER RETURN VAR NUMBER VAR VAR NUMBER VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
There are n heaps of stone. The i-th heap has h_i stones. You want to change the number of stones in the heap by performing the following process once:
* You go through the heaps from the 3-rd heap to the n-th heap, in this order.
* Let i be the number of the current heap.
* You can choose a number d (0 β€ 3 β
d β€ h_i), move d stones from the i-th heap to the (i - 1)-th heap, and 2 β
d stones from the i-th heap to the (i - 2)-th heap.
* So after that h_i is decreased by 3 β
d, h_{i - 1} is increased by d, and h_{i - 2} is increased by 2 β
d.
* You can choose different or same d for different operations. Some heaps may become empty, but they still count as heaps.
What is the maximum number of stones in the smallest heap after the process?
Input
Each test contains multiple test cases. The first line contains the number of test cases t (1 β€ t β€ 2β
10^5). Description of the test cases follows.
The first line of each test case contains a single integer n (3 β€ n β€ 2 β
10^5).
The second lines of each test case contains n integers h_1, h_2, h_3, β¦, h_n (1 β€ h_i β€ 10^9).
It is guaranteed that the sum of n over all test cases does not exceed 2 β
10^5.
Output
For each test case, print the maximum number of stones that the smallest heap can contain.
Example
Input
4
4
1 2 10 100
4
100 100 100 1
5
5 1 1 1 8
6
1 2 3 4 5 6
Output
7
1
1
3
Note
In the first test case, the initial heap sizes are [1, 2, 10, 100]. We can move the stones as follows.
* move 3 stones and 6 from the 3-rd heap to the 2-nd and 1 heap respectively. The heap sizes will be [7, 5, 1, 100];
* move 6 stones and 12 stones from the last heap to the 3-rd and 2-nd heap respectively. The heap sizes will be [7, 17, 7, 82].
In the second test case, the last heap is 1, and we can not increase its size.
In the third test case, it is better not to move any stones.
In the last test case, the final achievable configuration of the heaps can be [3, 5, 3, 4, 3, 3].
|
from sys import stdin
input = stdin.readline
def check(x):
value = a[:]
for i in range(n - 1, 1, -1):
if value[i] < x:
return False
this = min(a[i] // 3, max(0, (value[i] - x) // 3))
value[i - 1] += this
value[i - 2] += 2 * this
value[i] -= 3 * this
if value[0] < x or value[1] < x:
return False
return True
def answer():
l, h = 0, max(a)
while l <= h:
mid = (l + h) // 2
if check(mid):
ans = mid
l = mid + 1
else:
h = mid - 1
return ans
for T in range(int(input())):
n = int(input())
a = list(map(int, input().split()))
print(answer())
|
ASSIGN VAR VAR FUNC_DEF ASSIGN VAR VAR FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR RETURN NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER FUNC_CALL VAR NUMBER BIN_OP BIN_OP VAR VAR VAR NUMBER VAR BIN_OP VAR NUMBER VAR VAR BIN_OP VAR NUMBER BIN_OP NUMBER VAR VAR VAR BIN_OP NUMBER VAR IF VAR NUMBER VAR VAR NUMBER VAR RETURN NUMBER RETURN NUMBER FUNC_DEF ASSIGN VAR VAR NUMBER FUNC_CALL VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
a = list(map(int, input().split()))
d = [0] * 101
for i in a:
d[i] += 1
p = 0
while True:
allZeros = True
k = 0
for i in range(101):
if d[i] != 0:
while i >= k and d[i] > 0:
d[i] -= 1
k += 1
allZeros = False
if allZeros:
break
else:
p += 1
print(p)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER WHILE VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
boxes = [int(item) for item in input().split(" ")]
boxes.sort()
stacks = 0
while len(boxes):
stacks += 1
n_boxes = []
current_weight = 0
for box in boxes:
if box >= current_weight:
current_weight += 1
else:
n_boxes.append(box)
boxes = n_boxes
print(stacks)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
while len(l) != 0:
A = []
k = 1
ans += 1
for j in range(1, len(l)):
if l[j] != 0 and l[j] >= k:
k += 1
else:
A.append(l[j])
l = A
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
a = list(map(int, input().split()))
a.sort()
uni = {}
for elem in a:
if elem not in uni:
uni[elem] = 1
else:
uni[elem] += 1
piles = []
while len(a) > 0:
box = a.pop(0)
if len(piles) == 0:
piles.append([box])
else:
for i in range(len(piles)):
temp = piles[i]
if box >= len(temp):
temp.append(box)
piles[i] = temp
break
else:
piles.append([box])
print(len(piles))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR LIST WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR LIST VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
def Acc(arr):
arr.sort()
arr_aux = [(0) for i in range(len(arr))]
i = 0
j = 0
while i < len(arr):
if arr[i] >= arr_aux[j]:
arr_aux[j] = arr_aux[j] + 1
i += 1
j = 0
else:
j += 1
valor_actual = len(arr) - arr_aux.count(0)
print(valor_actual)
return
n = int(input())
arr = list(map(int, input().strip().split()))
Acc(arr)
|
FUNC_DEF EXPR FUNC_CALL VAR ASSIGN VAR NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP FUNC_CALL VAR VAR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR VAR RETURN ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
def isPossible(arr, pile):
arr.sort(reverse=True)
size = [10**18] * pile
c = 0
for item in arr:
if size[c % pile] >= 1:
size[c % pile] = min(size[c % pile] - 1, item)
else:
return False
c = c + 1
return True
n = int(input())
arr = [int(num) for num in input().split(" ")]
ans = n
while ans >= 1:
if isPossible(arr, ans) == True:
res = ans
else:
break
ans = ans - 1
print(res)
|
FUNC_DEF EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST BIN_OP NUMBER NUMBER VAR ASSIGN VAR NUMBER FOR VAR VAR IF VAR BIN_OP VAR VAR NUMBER ASSIGN VAR BIN_OP VAR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR NUMBER VAR RETURN NUMBER ASSIGN VAR BIN_OP VAR NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR VAR WHILE VAR NUMBER IF FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
def input_int_array():
return [int(string) for string in input().split()]
n = input_int_array()[0]
boxes = input_int_array()
counts = [0] * 101
for hardess in boxes:
counts[hardess] += 1
columns = []
for hardness in range(0, 101):
if counts[hardness] <= 0:
continue
for j in range(0, len(columns)):
while (len(columns[j]) <= hardness) & (counts[hardness] > 0):
counts[hardness] -= 1
columns[j].append(hardness)
while counts[hardness] > 0:
columns.append([hardness])
counts[hardness] -= 1
while (len(columns[-1]) <= hardness) & (counts[hardness] > 0):
columns[-1].append(hardness)
counts[hardness] -= 1
print(len(columns))
|
FUNC_DEF RETURN FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER NUMBER IF VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR WHILE BIN_OP FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR WHILE VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR VAR VAR NUMBER WHILE BIN_OP FUNC_CALL VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
def check(mid, lis):
pile = [10000000000] * mid
c = 0
for i in range(n - 1, -1, -1):
pile[i % mid] = min(pile[i % mid] - 1, lis[i])
if min(pile) < 0:
return 0
else:
return 1
n = int(input())
lis = sorted(map(int, input().split()))
l = 1
r = n
while l <= r:
mid = l + (r - l) // 2
if check(mid, lis):
r = mid - 1
else:
l = mid + 1
print(l)
|
FUNC_DEF 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 FUNC_CALL VAR BIN_OP VAR BIN_OP VAR VAR NUMBER VAR VAR IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR BIN_OP VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
ar = list(map(int, input().split(" ")))
ar.sort()
s = []
for i in ar:
s.sort(reverse=True)
for j in range(len(s)):
if i >= s[j]:
s[j] += 1
break
else:
s.append(1)
print(len(s))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
s = [int(c) for c in input().split()]
s.sort()
s.reverse()
ans = 1
def f(a):
i = 0
b = True
while i < len(a) and b:
if a[i] < len(a) - i - 1:
b = False
return b
i += 1
return b
while True:
p = [[] for i in range(ans)]
i = 0
while i < n:
p[i % ans].append(s[i])
i += 1
t = 0
for d in p:
if f(d):
t += 1
if t == len(p):
print(ans)
break
ans += 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FUNC_DEF ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR VAR IF VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR NUMBER RETURN VAR VAR NUMBER RETURN VAR WHILE NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR NUMBER IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
ip = input().split(" ")
ip2 = sorted(list(map(int, ip)))
count = 0
keys = set(ip2)
while len(ip2) != 0:
stack = []
for x in keys:
while len(stack) <= x and ip2.count(x) > 0:
stack.append(x)
del [ip2[ip2.index(x)]]
count = count + 1
print(count)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR LIST FOR VAR VAR WHILE FUNC_CALL VAR VAR VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
def main():
mode = "filee"
if mode == "file":
f = open("test.txt", "r")
get = lambda: [
int(x) for x in (f.readline() if mode == "file" else input()).split()
]
[n] = get()
a = get()
a.sort()
p = [[]]
p[0].append(a[0])
for i in a[1:]:
p = sorted(p, key=lambda x: len(x))
p.reverse()
found = False
for j in p:
if len(j) <= i:
j.append(i)
found = True
break
if found == False:
p.append([i])
print(len(p))
if mode == "file":
f.close()
main()
|
FUNC_DEF ASSIGN VAR STRING IF VAR STRING ASSIGN VAR FUNC_CALL VAR STRING STRING ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING FUNC_CALL VAR FUNC_CALL VAR ASSIGN LIST VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST LIST EXPR FUNC_CALL VAR NUMBER VAR NUMBER FOR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR LIST VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR STRING EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
a = list(map(int, input().split()))
st = 0
a.sort()
while len(a) != 0:
wt = 1
a[0] = "a"
for i in range(len(a)):
if a[i] != "a" and a[i] >= wt:
wt += 1
a[i] = "a"
for i in range(a.count("a")):
a.remove("a")
st += 1
print(st)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR STRING VAR VAR VAR VAR NUMBER ASSIGN VAR VAR STRING FOR VAR FUNC_CALL VAR FUNC_CALL VAR STRING EXPR FUNC_CALL VAR STRING VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
l = [int(x) for x in input().split()]
ans = 0
l.sort()
while l:
l1 = []
c = 0
for i in range(len(l)):
if l[i] >= c:
c += 1
else:
l1.append(l[i])
l = l1[:]
ans += 1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER EXPR FUNC_CALL VAR WHILE VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
import sys
input = sys.stdin.readline
read_tuple = lambda _type: map(_type, input().split(" "))
def is_correct(seq):
if len(seq) == 1:
return True
_len = 1
res = True
for idx in range(1, len(seq)):
res = res and seq[idx] >= _len
_len += 1
return res
def solve():
n = int(input())
x = list(read_tuple(int))
x.sort(reverse=True)
ans = 0
while x:
stack = [x.pop()]
while x:
added = False
for i in range(len(x) - 1, -1, -1):
if is_correct(stack + [x[i]]):
stack.append(x[i])
x.pop(i)
added = True
break
if not added:
break
ans += 1
print(ans)
solve()
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING FUNC_DEF IF FUNC_CALL VAR VAR NUMBER RETURN NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR VAR VAR NUMBER RETURN VAR FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR ASSIGN VAR LIST FUNC_CALL VAR WHILE VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER NUMBER NUMBER IF FUNC_CALL VAR BIN_OP VAR LIST VAR VAR EXPR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
a = [int(i) for i in input().split(" ")]
a.sort()
s = 1
for i in range(n):
if a[i] < i // s:
s += 1
print(s)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
a = [int(x) for x in input().split()]
v = [True] * n
a.sort()
ans = 0
prev = 0
i = 0
cnt = 0
while cnt < n:
if a[i] >= prev and v[i]:
cnt += 1
v[i] = False
prev += 1
i += 1
if i == n:
i = 0
prev = 0
ans += 1
if prev != 0:
ans += 1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
def validate_stack(stack):
for i in range(len(stack)):
if stack[i] < len(stack) - i - 1:
return False
return True
n = int(input())
box_strength = [int(x) for x in input().split()]
box_strength = sorted(box_strength, reverse=True)
flag = True
ans = 100
for i in range(1, n + 1):
matrix = [[] for x in range(i)]
flag = True
ans = i
for idx, j in enumerate(box_strength):
matrix[idx % i].append(j)
for stack in matrix:
if not validate_stack(stack):
flag = False
break
if flag:
break
print(ans)
|
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR FOR VAR VAR IF FUNC_CALL VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
unq, ans, req = set(arr), 1, 0
for ele in unq:
count = arr.count(ele)
req += count
if req // (ele + 1) != req / (ele + 1):
ans = max(1 + req // (ele + 1), ans)
else:
ans = max(req // (ele + 1), ans)
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR VAR FUNC_CALL VAR VAR NUMBER NUMBER FOR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR BIN_OP NUMBER BIN_OP VAR BIN_OP VAR NUMBER VAR ASSIGN VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 0
while len(l):
s = []
b = 0
for i in range(len(l)):
if b <= l[i]:
b = b + 1
else:
s.append(l[i])
ans = ans + bool(b)
l = s
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR FUNC_CALL VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
x = list(map(int, input().split()))
x.sort()
nu = 0
ans = 0
mark = []
for i in range(0, n):
mark.append(0)
for i in range(0, n):
fail = 1
nu = 0
for j in range(0, n):
if mark[j] == 0:
fail = 0
if x[j] >= nu:
nu += 1
mark[j] = 1
if fail == 0:
ans += 1
else:
break
print(ans)
|
ASSIGN VAR FUNC_CALL VAR 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 NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR NUMBER VAR EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
from sys import stdin
n = int(input())
a = list(map(int, stdin.readline().split()))
a.sort()
piles = 0
i = 0
while len(a) > 0:
piles += 1
boxes = 1
i = 0
del a[0]
while i < len(a):
if a[i] >= boxes:
boxes += 1
del a[i]
else:
i += 1
print(piles)
|
ASSIGN VAR FUNC_CALL VAR 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 NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
a = list(map(int, input().split()))
r = 0
flags = [False] * n
a.sort()
count = 0
for i in range(n):
if count == n:
break
r += 1
last = -1
for j in range(n):
if flags[j]:
continue
if a[j] == last:
continue
flags[j] = True
count += 1
last += 1
print(r)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR IF VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
ar = list(map(int, input().split()))
ar.sort()
stack = 0
chosen = [False] * n
for i in range(n):
chosen[i] = False
for i in range(n):
if chosen[i] == False:
chosen[i] = True
stack += 1
box = 1
for j in range(i, n):
if chosen[j] == False and ar[j] >= box:
chosen[j] = True
box += 1
print(stack)
|
ASSIGN VAR FUNC_CALL VAR 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 LIST NUMBER VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
l = list(map(int, input().split()))
l.sort()
i = 0
v = [0] * n
out = 0
while i < n:
if v[i] == 0:
c = 0
j = i
while j < n:
if l[j] >= c and v[j] == 0:
v[j] = 1
c += 1
j += 1
out += 1
i += 1
print(out)
|
ASSIGN VAR FUNC_CALL VAR 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 LIST NUMBER VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
mod = 1000000007
ii = lambda: int(input())
si = lambda: input()
dgl = lambda: list(map(int, input()))
f = lambda: map(int, input().split())
il = lambda: list(map(int, input().split()))
ls = lambda: list(input())
n = ii()
l = il()
vis = [0] * n
l.sort()
ans = 0
while any(i == 0 for i in vis):
cnt = 0
for i in range(n):
if vis[i] == 0 and l[i] >= cnt:
cnt += 1
vis[i] = 1
ans += 1
print(ans)
|
ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL 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 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 ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
a = sorted(map(int, input().split()))
c = 0
for i in range(n):
if (a[i] + 1) * c <= i:
c += 1
print(c)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF BIN_OP BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
arr = list(map(int, input().split()))
arr.sort(reverse=True)
vis = [False] * n
counter = 0
ans = 0
while counter < n:
ans += 1
init = 0
for i in range(n - 1, -1, -1):
if not vis[i] and arr[i] >= init:
vis[i] = True
counter += 1
init += 1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
l = list(map(int, input().split(" ")))
l.sort()
nb = 0
for i in range(n):
if l[i] == -1:
continue
h = 1
nb += 1
for j in range(i + 1, n):
if l[j] >= h:
h += 1
l[j] = -1
print(nb)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
I = lambda: list(map(int, input().split()))
(n,) = I()
l = I()
l.sort()
ans = 0
i = 0
k = 1
while i < n:
if l[i] < i // k:
k += 1
i += 1
print(k)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR BIN_OP VAR VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
import sys
input = sys.stdin.readline
li = lambda: list(map(int, input().split()))
n = int(input())
x = li()
x.sort()
def solve(n, x, num_piles):
piles = [x[-i] for i in range(1, num_piles + 1)]
for i in reversed(range(n - num_piles)):
xi = x[i]
best_pile = -1
best_index = None
for i, pile in enumerate(piles):
if pile > best_pile and pile > 0:
best_pile = pile
best_index = i
if best_index == None:
return False
else:
piles[best_index] = min(xi, best_pile - 1)
return True
for i in range(1, n):
if solve(n, x, i):
print(i)
sys.exit()
print(n)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_DEF ASSIGN VAR VAR VAR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR BIN_OP VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NONE FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR VAR IF VAR NONE RETURN NUMBER ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
N = int(input())
ar = list(map(int, input().split()))
ar.sort()
a = 1
b = 100
while a < b:
compliant = True
k = (a + b) // 2
for i in range(len(ar)):
if ar[i] < i // k:
compliant = False
break
if compliant:
b = k
else:
a = k + 1
print(b)
|
ASSIGN VAR FUNC_CALL VAR 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 NUMBER WHILE VAR VAR ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR ASSIGN VAR NUMBER IF VAR ASSIGN VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
num = int(input())
boxes = list(map(int, input().split()))
boxes.sort(reverse=True)
piles = []
while boxes:
box = boxes.pop()
for pile in piles:
if box >= len(pile):
pile.append(box)
break
else:
piles.append([box])
print(len(piles))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR LIST WHILE VAR ASSIGN VAR FUNC_CALL VAR FOR VAR VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
l = list(map(int, input().split()))
l = sorted(l)
l = l[::-1]
l1 = [0] * n
k = 0
for i in range(n):
if l1[i] != 1:
t = l[i]
p = 1
r = 0
l1[i] == 1
V = [t]
for j in range(n):
if l1[j] == 0 and l[j] < t:
t = l[j]
l1[j] = 1
V.append(t)
r = r + 1
for j in range(n - 1, -1, -1):
if l1[j] != 1:
if l[j] in V:
q = V.index(l[j]) + 1
if len(V) - q + 1 <= l[j]:
c = 0
s = -1
u = len(V) - q + 1
for e in range(q - 1, -1, -1):
if V[e] >= u + s:
s = s + 1
else:
c = 1
break
if c == 0:
l1[j] = 1
V = V[: q - 1] + [l[j]] + V[q - 1 :]
k = k + 1
print(k)
|
ASSIGN VAR FUNC_CALL VAR 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 VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR VAR VAR NUMBER ASSIGN VAR LIST VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER VAR VAR VAR ASSIGN VAR VAR VAR ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR NUMBER IF VAR VAR VAR ASSIGN VAR BIN_OP FUNC_CALL VAR VAR VAR NUMBER IF BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER NUMBER NUMBER IF VAR VAR BIN_OP VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR BIN_OP VAR NUMBER LIST VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
input()
s = []
for x in sorted(map(int, input().split())):
if len(s) == 0:
s.append(1)
else:
for i in range(len(s)):
if x >= s[i]:
s[i] += 1
break
else:
s.append(1)
print(len(s))
|
EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
pile, tc = 0, n
visited = [0] * n
while tc != 0:
tt = 0
for i in range(0, n):
if a[i] >= tt and visited[i] != 1:
visited[i] = 1
tt += 1
tc -= 1
if tt > 0:
pile += 1
print(pile)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR ASSIGN VAR BIN_OP LIST NUMBER VAR WHILE VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER VAR NUMBER IF VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = input()
h = [0]
A = list(map(int, input().split()))
A.sort()
for x in A:
if x < min(h):
h += [1]
else:
h[h.index(min(h))] += 1
print(len(h))
|
ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR LIST NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
l_b = list(map(int, input().split()))
l_b.sort()
p = 0
s_d = list()
while len(l_b) > 0:
t = 0
for i, b in enumerate(l_b):
if b >= t:
s_d.append(i)
t += 1
for i in s_d[::-1]:
del l_b[i]
s_d = list()
p += 1
print(p)
|
ASSIGN VAR FUNC_CALL VAR 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 FUNC_CALL VAR WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER FOR VAR VAR NUMBER VAR VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
def main():
n = int(input())
boxes = sorted(list(map(int, input().split())))
remaining = []
in_use = []
ans = 0
while boxes:
for i in boxes:
if len(in_use) <= i:
in_use.append(i)
else:
remaining.append(i)
ans += 1
boxes = remaining
remaining = []
in_use = []
print(ans)
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR FOR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
import sys
t = 1
mod = 10**9 + 7
for __ in range(t):
n = int(input())
l = list(map(int, input().split()))
l.sort()
cnt = 0
maxi = 0
ans = 0
while cnt < n:
cnt1 = 0
for i in range(n):
if l[i] != -1:
if l[i] >= cnt1:
cnt += 1
cnt1 += 1
l[i] = -1
ans += 1
print(ans)
|
IMPORT ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR 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 NUMBER ASSIGN VAR NUMBER WHILE VAR VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
l = [int(i) for i in input().split()]
l.sort()
piles = []
for x in l:
if x == 0:
piles.append(1)
continue
f = 0
for i in range(len(piles)):
if piles[i] <= x:
piles[i] += 1
f = 1
break
if not f:
piles.append(1)
print(len(piles))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
from sys import stdin, stdout
nmbr = lambda: int(stdin.readline())
lst = lambda: list(map(int, input().split()))
for _ in range(1):
n = nmbr()
a = sorted(lst())
ans = 0
while 1:
left = []
cap = 0
for v in a:
if v >= cap:
cap += 1
else:
left += [v]
a = left.copy()
ans += 1
if len(left) == 0:
break
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR VAR IF VAR VAR VAR NUMBER VAR LIST VAR ASSIGN VAR FUNC_CALL VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
l = [int(x) for x in input().split()]
l.sort()
u = 0
a = 0
while u < n:
a += 1
c = 0
for i in range(n):
if l[i] >= c:
c += 1
u += 1
l[i] = -1
print(a)
|
ASSIGN VAR FUNC_CALL VAR 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 WHILE VAR VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
temparr = input()
temparr = temparr.split()
arr = []
for i in temparr:
arr.append(int(i))
arr = sorted(arr)
revarr = arr[::-1]
mins = len(arr)
left = 0
right = mins
while left <= right:
temp = []
flag = 0
mid = (left + right) // 2
nexts = 0
index = 0
for i in range(mid):
temp.append([revarr[i], 0, revarr[i]])
index += 1
flag = 0
newindex = -1
for i in range(index, n):
flag = 0
newindex += 1
for k in range(mid):
j = (newindex + k) % mid
if temp[j][0] > temp[j][1] and revarr[i] < temp[j][0] and temp[j][2] >= 1:
flag = 1
temp[j][0] = revarr[i]
temp[j][1] = 0
temp[j][2] -= 1
elif (
temp[j][0] > temp[j][1] and revarr[i] == temp[j][0] and temp[j][2] >= 1
):
flag = 1
temp[j][1] += 1
temp[j][2] -= 1
if flag == 1:
break
if flag == 0:
break
if flag == 0:
left = mid + 1
else:
mins = min(mid, mins)
right = mid - 1
print(mins)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR LIST FOR VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR VAR NUMBER VAR VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER VAR VAR ASSIGN VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER IF VAR VAR NUMBER VAR VAR NUMBER VAR VAR VAR VAR NUMBER VAR VAR NUMBER NUMBER ASSIGN VAR NUMBER VAR VAR NUMBER NUMBER VAR VAR NUMBER NUMBER IF VAR NUMBER IF VAR NUMBER IF VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
N = int(input())
a = list(map(int, input().split()))
a.sort()
k = 1
while True:
for i in range(len(a)):
if a[i] < i // k:
break
else:
print(k)
break
k += 1
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = map(int, input().split())
x = sorted(list(map(int, input().split())))
piles = 1
current = x.pop(0)
current_size = 1
while x:
for i, e in enumerate(x):
if e >= current_size:
current = e
x.pop(i)
current_size += 1
break
else:
current = x[0]
x.pop(0)
current_size = 1
piles += 1
print(piles)
|
ASSIGN 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 NUMBER ASSIGN VAR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR VAR ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR NUMBER ASSIGN VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
import sys
input = sys.stdin.readline
I = lambda: list(map(int, input().split()))
(n,) = I()
l = sorted(I())
an = 1
c = 1
cr = l[0]
i = 1
while i < n:
if l[i] > l[i - 1]:
an = max(an, (c + cr) // (cr + 1))
cr = l[i]
c += 1
i += 1
an = max(an, (c + cr) // (cr + 1))
print(an)
|
IMPORT ASSIGN VAR VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR BIN_OP VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER ASSIGN VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP VAR VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
s = input().split(" ")
for i in range(0, n):
s[i] = int(s[i])
s = sorted(s)
a = []
tt = 0
for i in range(0, n):
c = 0
for j in range(tt, len(a)):
if s[i] > a[j]:
a[j] += 1
c = 1
break
if c == 0:
a.append(0)
print(len(a))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR STRING FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR VAR FUNC_CALL VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
boxes = list(map(int, input().split()))
cont = 1
i = 1
boxes.sort()
for i in range(n):
if i // cont > boxes[i]:
cont = cont + 1
print(cont)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR VAR IF BIN_OP VAR VAR VAR VAR ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
a = list(map(int, input().split()))
a.sort()
counter = 0
while len(a) != 0:
numbers = {-1}
for elements in a:
numbers.add(elements)
numbers.remove(-1)
for values in numbers:
a.remove(values)
j = 0
s = 0
for values in numbers:
if len(a) == 0:
break
for x in range(values - s):
if len(a) == 0:
break
i = 0
while i < len(a):
if a[i] >= j:
a.remove(a[i])
j += 1
break
else:
i += 1
j += 1
s = j
counter += 1
print(counter)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER FOR VAR VAR EXPR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR VAR IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR FUNC_CALL VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
a = list(map(int, input().split()))
a.sort()
res = 0
for i in range(n):
cnt = i + 1
lvl = a[i] + 1
res = max(res, (cnt + lvl - 1) // lvl)
print(res)
|
ASSIGN VAR FUNC_CALL VAR 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 FUNC_CALL VAR VAR ASSIGN VAR BIN_OP VAR NUMBER ASSIGN VAR BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR BIN_OP BIN_OP BIN_OP VAR VAR NUMBER VAR EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
x = sorted(list(map(int, input().split())))
a = [0] * n
ans = 0
for i in range(n):
ok = False
for j in range(ans):
if x[i] >= a[j]:
a[j] += 1
ok = True
break
if ok == False:
ans += 1
a[ans - 1] = 1
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL 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 VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR NUMBER VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
arr = list(map(int, input().split()))
arr.sort()
for k in range(1, n + 1):
i = 0
v = 0
ok = True
while i < n:
for j in range(i, min(i + k, n)):
if arr[j] < v:
ok = False
break
i += k
v += 1
if ok:
print(k)
exit()
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR FOR VAR FUNC_CALL VAR VAR FUNC_CALL VAR BIN_OP VAR VAR VAR IF VAR VAR VAR ASSIGN VAR NUMBER VAR VAR VAR NUMBER IF VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
from sys import stdin
inFile = stdin
tokens = []
tokens_next = 0
def next_str():
global tokens, tokens_next
while tokens_next >= len(tokens):
tokens = inFile.readline().split()
tokens_next = 0
tokens_next += 1
return tokens[tokens_next - 1]
def nextInt():
return int(next_str())
def check(a, n):
if n == 0:
return 0
if len(a) <= n:
return 1
l = [[i] for i in a[:n]]
allowed = [i for i in a[:n]]
ind = 0
for i in a[n:]:
ind += 1
ind %= len(allowed)
starting_pos = ind
while allowed[ind] == 0:
ind += 1
ind %= len(l)
if ind == starting_pos:
return 0
l[ind] += [i]
allowed[ind] = min(i, allowed[ind] - 1)
return 1
def solve(a):
a.sort(reverse=1)
n = len(a)
low = 0
high = n
while low + 1 < high:
m = (low + high) // 2
if check(a, m):
high = m
else:
low = m
return high
n = nextInt()
a = [nextInt() for i in range(n)]
print(solve(a))
|
ASSIGN VAR VAR ASSIGN VAR LIST ASSIGN VAR NUMBER FUNC_DEF WHILE VAR FUNC_CALL VAR VAR ASSIGN VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER VAR NUMBER RETURN VAR BIN_OP VAR NUMBER FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR FUNC_DEF IF VAR NUMBER RETURN NUMBER IF FUNC_CALL VAR VAR VAR RETURN NUMBER ASSIGN VAR LIST VAR VAR VAR VAR ASSIGN VAR VAR VAR VAR VAR ASSIGN VAR NUMBER FOR VAR VAR VAR VAR NUMBER VAR FUNC_CALL VAR VAR ASSIGN VAR VAR WHILE VAR VAR NUMBER VAR NUMBER VAR FUNC_CALL VAR VAR IF VAR VAR RETURN NUMBER VAR VAR LIST VAR ASSIGN VAR VAR FUNC_CALL VAR VAR BIN_OP VAR VAR NUMBER RETURN NUMBER FUNC_DEF EXPR FUNC_CALL VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER ASSIGN VAR VAR WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER IF FUNC_CALL VAR VAR VAR ASSIGN VAR VAR ASSIGN VAR VAR RETURN VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
arr = [int(i) for i in input().split()]
arr.sort()
for i in range(1, n + 1):
temp = []
l = n - 1
for j in range(i):
temp.append(arr[l])
l -= 1
boo = True
while l >= 0 and boo:
boo = False
for j in range(i):
if temp[j] > 0:
boo = True
temp[j] = min(temp[j] - 1, arr[l])
l -= 1
if l < 0:
print(i)
break
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER ASSIGN VAR LIST ASSIGN VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER WHILE VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR FUNC_CALL VAR BIN_OP VAR VAR NUMBER VAR VAR VAR NUMBER IF VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
a = list(map(int, input().split()))
sm = 1
b = [(0) for i in range(101)]
for i in range(n):
b[a[i]] += 1
x = [0] * n
z = 0
zm = 0
for i in range(101):
while b[i] != 0:
if x[z] > i:
z += 1
zm = max(zm, z)
if x[z] <= i and b[i] > 0:
x[z] += 1
b[i] -= 1
z = 0
print(zm + 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER VAR FUNC_CALL VAR NUMBER FOR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER ASSIGN VAR BIN_OP LIST NUMBER VAR ASSIGN VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER WHILE VAR VAR NUMBER IF VAR VAR VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR IF VAR VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR NUMBER
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
nums = sorted(list(map(int, input().split(" "))))
v = []
b = [0] * 105
cnt = 0
k = 0
while cnt < n:
k += 1
for i in range(n):
if nums[i] >= len(v) and b[i] == 0:
v.append(nums[i])
b[i] = 1
cnt += 1
v = []
print(k)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR STRING ASSIGN VAR LIST ASSIGN VAR BIN_OP LIST NUMBER NUMBER ASSIGN VAR NUMBER ASSIGN VAR NUMBER WHILE VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
def take_lightest_box(boxes):
for i in range(101):
if i in boxes:
boxes[i] -= 1
if boxes[i] == 0:
del boxes[i]
return i
piles = []
boxes = {}
input()
tmp = input()
x = [int(i) for i in tmp.split(" ")]
for item in x:
if item in boxes:
boxes[item] = boxes[item] + 1
else:
boxes[item] = 1
while len(boxes) > 0:
lightest = take_lightest_box(boxes)
for pile in piles:
if len(pile) <= lightest:
pile.append(lightest)
break
else:
piles.append([lightest])
print(len(piles))
|
FUNC_DEF FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR VAR VAR NUMBER IF VAR VAR NUMBER VAR VAR RETURN VAR ASSIGN VAR LIST ASSIGN VAR DICT EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL VAR STRING FOR VAR VAR IF VAR VAR ASSIGN VAR VAR BIN_OP VAR VAR NUMBER ASSIGN VAR VAR NUMBER WHILE FUNC_CALL VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR FOR VAR VAR IF FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR LIST VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
def main():
n = int(input())
l = sorted(map(int, input().split()))
res = 0
while l:
res += 1
i, l1 = 0, []
for x in l:
if x < i:
l1.append(x)
else:
i += 1
l = l1
print(res)
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR NUMBER WHILE VAR VAR NUMBER ASSIGN VAR VAR NUMBER LIST FOR VAR VAR IF VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER ASSIGN VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
ar = list(map(int, input().strip().split(" ")))
ar.sort()
i = 0
li = list()
cnt = [0] * 101
for i in ar:
cnt[i] += 1
for i in range(101):
if cnt[i] == 0:
continue
if len(li) == 0:
x = i + 1
li.extend([x] * (cnt[i] // x))
if cnt[i] % x != 0:
li.append(cnt[i] % x)
else:
z = len(li)
for j in range(z):
x = i - li[j] + 1
if x < cnt[i]:
cnt[i] -= x
li[j] += x
else:
li[j] += cnt[i]
cnt[i] = 0
break
if cnt[i] != 0:
d = cnt[i]
li.extend([i + 1] * (d // (i + 1)))
if d % (i + 1) != 0:
li.append(d % (i + 1))
print(len(li))
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR STRING EXPR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER IF VAR VAR NUMBER IF FUNC_CALL VAR VAR NUMBER ASSIGN VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR BIN_OP LIST VAR BIN_OP VAR VAR VAR IF BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR ASSIGN VAR FUNC_CALL VAR VAR FOR VAR FUNC_CALL VAR VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR VAR NUMBER IF VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR VAR ASSIGN VAR VAR NUMBER IF VAR VAR NUMBER ASSIGN VAR VAR VAR EXPR FUNC_CALL VAR BIN_OP LIST BIN_OP VAR NUMBER BIN_OP VAR BIN_OP VAR NUMBER IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
a = sorted(list(map(int, input().split())))
used = [False] * (n + 1)
ans = 0
while True:
pos = -1
for i in range(n):
if used[i] == False:
pos = i
break
if pos == -1:
break
ans += 1
total = 1
used[pos] = True
for j in range(pos + 1, n):
if used[j] == False and a[j] >= total:
total += 1
used[j] = True
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR 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 WHILE NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR NUMBER ASSIGN VAR VAR IF VAR NUMBER VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR NUMBER VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
l = sorted(list(map(int, input().split())))
piles = [None] * 100
for i in range(1, 100):
piles[i] = []
piles[0] = [l[0]]
i = 1
for j in range(1, n):
flag = 0
for k in range(0, i):
if l[j] >= len(piles[k]):
piles[k].append(l[j])
flag = 1
break
if flag == 0:
piles[i] = [l[j]]
i += 1
print(i)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR BIN_OP LIST NONE NUMBER FOR VAR FUNC_CALL VAR NUMBER NUMBER ASSIGN VAR VAR LIST ASSIGN VAR NUMBER LIST VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR NUMBER VAR IF VAR VAR FUNC_CALL VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR ASSIGN VAR NUMBER IF VAR NUMBER ASSIGN VAR VAR LIST VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
a = sorted(map(int, input().split()), reverse=True)
def ok(cnt):
stacks = [[] for _ in range(cnt)]
for i, val in enumerate(a):
stacks[i % cnt].append(val)
for stack in stacks:
for i, val in enumerate(stack):
if val < len(stack) - i - 1:
return False
return True
for i in range(1, n + 1):
if ok(i):
print(i)
exit()
raise Exception
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR NUMBER FUNC_DEF ASSIGN VAR LIST VAR FUNC_CALL VAR VAR FOR VAR VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR BIN_OP VAR VAR VAR FOR VAR VAR FOR VAR VAR FUNC_CALL VAR VAR IF VAR BIN_OP BIN_OP FUNC_CALL VAR VAR VAR NUMBER RETURN NUMBER RETURN NUMBER FOR VAR FUNC_CALL VAR NUMBER BIN_OP VAR NUMBER IF FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
def check(a, x):
for i in range(len(a)):
if a[i] < len(a) - i:
return False
return True
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
piles = []
for i in a:
if len(piles) == 0:
piles.append([i])
else:
flg = 1
for j in range(len(piles)):
if len(piles[j]) <= i:
piles[j].append(i)
flg = 0
break
if flg:
piles.append([i])
print(len(piles))
|
FUNC_DEF FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP FUNC_CALL VAR VAR VAR RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR 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 FOR VAR VAR IF FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR LIST VAR ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR ASSIGN VAR NUMBER IF VAR EXPR FUNC_CALL VAR LIST VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
A = [int(a) for a in input().split()]
A.sort()
piles = 0
for i in range(n):
if A[i] == -1:
continue
size = 1
A[i] = -1
for j in range(i + 1, n):
if A[j] < size:
continue
elif A[j] > size:
size += 1
A[j] = -1
elif A[j] == size and A[j] > 0:
size += 1
A[j] = -1
else:
size += 1
A[j] = -1
piles += 1
print(piles)
|
ASSIGN VAR FUNC_CALL VAR 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 VAR IF VAR VAR NUMBER ASSIGN VAR NUMBER ASSIGN VAR VAR NUMBER FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER VAR IF VAR VAR VAR IF VAR VAR VAR VAR NUMBER ASSIGN VAR VAR NUMBER IF VAR VAR VAR VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
def fox(lst):
result = 1
for i in range(len(lst)):
if lst[i] < i // result:
result += 1
return result
n = int(input())
a = [int(j) for j in input().split()]
print(fox(sorted(a)))
|
FUNC_DEF ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
listn = list(map(int, input().split()))
listn = sorted(listn)
i = 0
res = 0
vis = []
while i < n:
res += 1
currPile = []
k = 0
while k < n:
if listn[k] >= len(currPile) and not k in vis:
i += 1
vis.append(k)
currPile.append(1)
k += 1
print(res)
|
ASSIGN VAR FUNC_CALL VAR 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 ASSIGN VAR NUMBER ASSIGN VAR LIST WHILE VAR VAR VAR NUMBER ASSIGN VAR LIST ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR FUNC_CALL VAR VAR VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
from sys import stdin
def get_freq(arr):
freq = [0] * 101
for i in arr:
freq[i] += 1
return freq
n = int(stdin.readline().strip())
arr = list(map(int, stdin.readline().split()))
freq = get_freq(arr)
i = 0
c = 0
while i <= 100:
if freq[i] == 0:
i += 1
else:
freq[i] -= 1
c += 1
j = i
strength = 1
while j <= 100:
if j >= strength and freq[j] > 0:
freq[j] -= 1
strength += 1
continue
j += 1
print(c)
|
FUNC_DEF ASSIGN VAR BIN_OP LIST NUMBER NUMBER FOR VAR VAR VAR VAR NUMBER RETURN VAR ASSIGN VAR FUNC_CALL 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 ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR NUMBER VAR NUMBER VAR VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR NUMBER WHILE VAR NUMBER IF VAR VAR VAR VAR NUMBER VAR VAR NUMBER VAR NUMBER VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
ans = 0
li1 = [int(i) for i in input().split()]
li2 = []
while li1:
li1.sort()
n = len(li1)
i = 0
while i < n:
if li1[i] < i:
li2.append(li1[i])
del li1[i]
n -= 1
else:
i += 1
ans += 1
li1 = li2
li2 = []
print(ans)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR LIST WHILE VAR EXPR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR VAR ASSIGN VAR NUMBER WHILE VAR VAR IF VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR VAR VAR NUMBER VAR NUMBER VAR NUMBER ASSIGN VAR VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n, required, searched = int(input()), 0, []
boxes = list(sorted([int(i) for i in input().split()]))
while True:
stack = 0
for i in range(n):
if i not in searched and boxes[i] >= stack:
searched.append(i)
stack += 1
if stack:
required += 1
else:
break
print(required)
|
ASSIGN VAR VAR VAR FUNC_CALL VAR FUNC_CALL VAR NUMBER LIST ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR WHILE NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR VAR IF VAR VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR NUMBER IF VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
input()
print(
max(
[
((ind + 1) // (i + 1) + ((ind + 1) % (i + 1) != 0))
for ind, i in enumerate(sorted(map(int, input().split())))
]
)
)
|
EXPR FUNC_CALL VAR EXPR FUNC_CALL VAR FUNC_CALL VAR BIN_OP BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER BIN_OP BIN_OP VAR NUMBER BIN_OP VAR NUMBER NUMBER VAR VAR FUNC_CALL VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
t = 1
while t:
t -= 1
n = int(input())
l = list(map(int, input().split()))
l.sort()
ans = 1
for i in range(n):
if l[i] < i // ans:
ans += 1
print(ans)
|
ASSIGN VAR NUMBER WHILE VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR 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 FUNC_CALL VAR VAR IF VAR VAR BIN_OP VAR VAR VAR NUMBER EXPR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
def main():
n = int(input())
strength = list(map(int, input().split()))
strengths = {}
for i in strength:
if i not in strengths.keys():
strengths[i] = 1
else:
strengths[i] += 1
boxes = []
for i in strengths.keys():
boxes.append([i, strengths[i]])
boxes.sort()
piles = []
piles.append([boxes[0][0]])
boxes[0][1] -= 1
for i in range(len(boxes)):
curr = boxes[i][0]
count = boxes[i][1]
while count > 0:
found = False
for j in range(len(piles)):
if count > 0:
if len(piles[j]) <= curr:
piles[j].append(curr)
count -= 1
found = True
if not found:
break
if count > 0:
total = count // (curr + 1)
for j in range(total):
pile = []
for k in range(curr + 1):
pile.append(curr)
piles.append(pile)
if count % (curr + 1) != 0:
pile = []
for j in range(count % (curr + 1)):
pile.append(curr)
piles.append(pile)
print(len(piles))
main()
|
FUNC_DEF ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR ASSIGN VAR DICT FOR VAR VAR IF VAR FUNC_CALL VAR ASSIGN VAR VAR NUMBER VAR VAR NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR EXPR FUNC_CALL VAR LIST VAR VAR VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST EXPR FUNC_CALL VAR LIST VAR NUMBER NUMBER VAR NUMBER NUMBER NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR NUMBER ASSIGN VAR VAR VAR NUMBER WHILE VAR NUMBER ASSIGN VAR NUMBER FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR IF VAR NUMBER IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR VAR VAR NUMBER ASSIGN VAR NUMBER IF VAR IF VAR NUMBER ASSIGN VAR BIN_OP VAR BIN_OP VAR NUMBER FOR VAR FUNC_CALL VAR VAR ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF BIN_OP VAR BIN_OP VAR NUMBER NUMBER ASSIGN VAR LIST FOR VAR FUNC_CALL VAR BIN_OP VAR BIN_OP VAR NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
import sys
inf = float("inf")
words = {
(1): "one",
(2): "two",
(3): "three",
(4): "four",
(5): "five",
(6): "six",
(7): "seven",
(8): "eight",
(9): "nine",
(10): "ten",
(11): "eleven",
(12): "twelve",
(13): "thirteen",
(14): "fourteen",
(15): "quarter",
(16): "sixteen",
(17): "seventeen",
(18): "eighteen",
(19): "nineteen",
(20): "twenty",
(21): "twenty one",
(22): "twenty two",
(23): "twenty three",
(24): "twenty four",
(25): "twenty five",
(26): "twenty six",
(27): "twenty seven",
(28): "twenty eight",
(29): "twenty nine",
(30): "half",
}
def get_array():
return list(map(int, sys.stdin.readline().strip().split()))
def get_ints():
return map(int, sys.stdin.readline().strip().split())
def input():
return sys.stdin.readline().strip()
n = int(input())
Arr = get_array()
Arr.sort()
h = [0]
for x in Arr:
if x < min(h):
h += [1]
else:
h[h.index(min(h))] += 1
print(len(h))
|
IMPORT ASSIGN VAR FUNC_CALL VAR STRING ASSIGN VAR DICT NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER NUMBER STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING STRING FUNC_DEF RETURN FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL FUNC_CALL VAR FUNC_DEF RETURN FUNC_CALL FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR EXPR FUNC_CALL VAR ASSIGN VAR LIST NUMBER FOR VAR VAR IF VAR FUNC_CALL VAR VAR VAR LIST NUMBER VAR FUNC_CALL VAR FUNC_CALL VAR VAR NUMBER EXPR FUNC_CALL VAR FUNC_CALL VAR VAR
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
n = int(input())
val = [[]]
for x in sorted(int(x) for x in input().split()):
for l in val:
if x >= len(l):
l.append(x)
break
if len(val[-1]) > 0:
val.append([])
print(len(val) - 1)
|
ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR LIST LIST FOR VAR FUNC_CALL VAR FUNC_CALL VAR VAR VAR FUNC_CALL FUNC_CALL VAR FOR VAR VAR IF VAR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR VAR IF FUNC_CALL VAR VAR NUMBER NUMBER EXPR FUNC_CALL VAR LIST EXPR FUNC_CALL VAR BIN_OP FUNC_CALL VAR VAR NUMBER
|
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box).
Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile.
<image>
Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct?
Input
The first line contains an integer n (1 β€ n β€ 100). The next line contains n integers x1, x2, ..., xn (0 β€ xi β€ 100).
Output
Output a single integer β the minimal possible number of piles.
Examples
Input
3
0 0 10
Output
2
Input
5
0 1 2 3 4
Output
1
Input
4
0 0 0 0
Output
4
Input
9
0 1 0 2 0 1 1 2 10
Output
3
Note
In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2.
<image>
In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom).
<image>
|
def b(a, la, n):
for i in range(n):
b = a[i::n]
ll = (la - i + n - 1) // n
for j in range(ll):
if b[j] < ll - j - 1:
return False
return True
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
l, r = 1, n
if b(a, n, l):
print(l)
exit()
if b(a, n, r - 1) == False:
print(r)
exit()
while l + 1 < r:
h = (l + r) // 2
q = b(a, n, h)
if q:
r = h
else:
l = h
print(r)
|
FUNC_DEF FOR VAR FUNC_CALL VAR VAR ASSIGN VAR VAR VAR VAR ASSIGN VAR BIN_OP BIN_OP BIN_OP BIN_OP VAR VAR VAR NUMBER VAR FOR VAR FUNC_CALL VAR VAR IF VAR VAR BIN_OP BIN_OP VAR VAR NUMBER RETURN NUMBER RETURN NUMBER ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR ASSIGN VAR FUNC_CALL VAR FUNC_CALL VAR VAR FUNC_CALL FUNC_CALL VAR EXPR FUNC_CALL VAR NUMBER ASSIGN VAR VAR NUMBER VAR IF FUNC_CALL VAR VAR VAR VAR EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR IF FUNC_CALL VAR VAR VAR BIN_OP VAR NUMBER NUMBER EXPR FUNC_CALL VAR VAR EXPR FUNC_CALL VAR WHILE BIN_OP VAR NUMBER VAR ASSIGN VAR BIN_OP BIN_OP VAR VAR NUMBER ASSIGN VAR FUNC_CALL VAR VAR VAR VAR IF VAR ASSIGN VAR VAR ASSIGN 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.