Search is not available for this dataset
name
stringlengths 2
112
| description
stringlengths 29
13k
| source
int64 1
7
| difficulty
int64 0
25
| solution
stringlengths 7
983k
| language
stringclasses 4
values |
---|---|---|---|---|---|
389_C. Fox and Box Accumulation | 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> | 2 | 9 | 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
| PYTHON3 |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | 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) | PYTHON3 |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | n=input()
d=sorted(map(int,raw_input().split()))
for k in range(1,101):
b=1
for i in range(n):
if d[i] < i/k:
b=0
if b:
print k
exit(0) | PYTHON |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
import java.util.Map.Entry;
public class zz{
public static void main(String[] args) throws IOException{
MScanner sc = new MScanner(System.in);
PrintWriter pw=new PrintWriter(System.out);
int n=sc.nextInt();
int[]nums=new int[101];
for(int i=0;i<n;i++) {
nums[sc.nextInt()]++;
}
int p=0;
for(int i=0;i<101;i++) {
if(n>0) {
p++;
int taken=0;
for(int j=0;j<101;j++) {
while(nums[j]>0 && j>=taken) {
nums[j]--;n--;taken++;
}
}
}
else {
break;
}
}
pw.println(p);
pw.flush();
}
static class MScanner
{
StringTokenizer st;
BufferedReader br;
public MScanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));}
public String next() throws IOException
{
while (st == null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public int nextInt() throws IOException {return Integer.parseInt(next());}
public long nextLong() throws IOException {return Long.parseLong(next());}
public String nextLine() throws IOException {return br.readLine();}
public double nextDouble() throws IOException
{
String x = next();
StringBuilder sb = new StringBuilder("0");
double res = 0, f = 1;
boolean dec = false, neg = false;
int start = 0;
if(x.charAt(0) == '-')
{
neg = true;
start++;
}
for(int i = start; i < x.length(); i++)
if(x.charAt(i) == '.')
{
res = Long.parseLong(sb.toString());
sb = new StringBuilder("0");
dec = true;
}
else
{
sb.append(x.charAt(i));
if(dec)
f *= 10;
}
res += Long.parseLong(sb.toString()) / f;
return res * (neg?-1:1);
}
public boolean ready() throws IOException {return br.ready();}
}
} | JAVA |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
int n, arr[200];
while (cin >> n) {
int ans = 0, arr1[200];
for (int i = 0; i < n; i++) cin >> arr[i];
sort(arr, arr + n);
for (int i = 0; i < n; i++) {
bool flag = 0;
for (int j = 0; j < ans; j++) {
if (arr1[j] <= arr[i]) {
arr1[j]++;
flag = 1;
break;
}
}
if (!flag) {
arr1[ans++] = 1;
}
}
cout << ans << endl;
}
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | R=lambda:map(int,raw_input().split())
n = input()
a = R()
a.sort()
res = 1
l = [[a[0]]]
for i in range(1, n):
ins = False
for j in range(len(l)):
if len(l[j]) <= a[i]:
l[j].append(a[i])
ins = True
break
if not ins:
l.append([a[i]])
print len(l) | PYTHON |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int data[100];
int freq[101];
int min(int a, int b) {
if (a < 0) return 0;
if (b < 0) return 0;
if (a < b) return a;
return b;
}
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", data + i);
for (int i = 0; i < 101; i++) freq[i] = 0;
for (int i = 0; i < n; i++) freq[data[i]]++;
int g = 0;
while (1) {
int i;
for (i = 0; i < 101; i++) {
if (freq[i]) break;
}
if (i == 101) break;
int add = 0;
for (; i < 101; i++)
if ((freq[i]) && (i >= add)) {
int tmp = min(i + 1 - add, freq[i]);
add += tmp;
freq[i] -= tmp;
}
g++;
}
printf("%d\n", g);
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
inline bool EQ(double a, double b) { return fabs(a - b) < 1e-9; }
const int INF = 1 << 29;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n >> b) & 1; }
inline void set_bit(int& n, int b) { n |= two(b); }
inline void unset_bit(int& n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) {
int res = 0;
while (n && ++res) n -= n & (-n);
return res;
}
template <class T>
void chmax(T& a, const T& b) {
a = max(a, b);
}
template <class T>
void chmin(T& a, const T& b) {
a = min(a, b);
}
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
x += 0x9e3779b97f4a7c15;
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const {
static const uint64_t FIXED_RANDOM =
chrono::steady_clock::now().time_since_epoch().count();
return splitmix64(x + FIXED_RANDOM);
}
};
int mulmd(long long a, long long b) {
long long ret = (a * b) % 1000000007;
return (int)ret;
}
inline int power(long long x, long long y, int p) {
long long res = 1;
x = x % p;
while (y > 0) {
if (y & 1) res = mulmd(res, x);
y = y >> 1;
x = mulmd(x, x);
}
return (int)res;
}
int submd(long long a, long long b) {
long long ret = a - b;
if (ret < 0) {
ret += 1000000007;
}
return (int)ret;
}
int addmd(long long a, long long b) {
long long ret = (a + b) % 1000000007;
return (int)ret;
}
int phi(int n) {
int result = n;
for (int i = 2; i * i <= n; i++) {
if (n % i == 0) {
while (n % i == 0) {
n = n / i;
}
result -= result / i;
}
}
if (n > 1) result -= result / n;
return result;
}
int gcd(int a, int b, int& x, int& y) {
if (a == 0) {
x = 0;
y = 1;
return b;
}
int x1, y1;
int d = gcd(b % a, a, x1, y1);
x = y1 - (b / a) * x1;
y = x1;
return d;
}
int arr[100005];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
unordered_map<int, int, custom_hash> a;
for (int i = 0; i < (n); i++) {
cin >> arr[i];
a[arr[i]]++;
}
sort(arr, arr + n);
vector<int> d;
d.push_back(0);
for (int i = 0; i < n; i++) {
int f = 0;
for (int j = 0; j < d.size(); j++) {
if (arr[i] >= d[j]) {
d[j]++;
f = 1;
break;
}
}
if (f == 0) {
d.push_back(1);
}
}
cout << d.size();
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int a[110];
int vis[110];
int n;
int main() {
int i, j;
while (scanf("%d", &n) != EOF) {
memset(vis, 0, sizeof(vis));
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
sort(a + 1, a + n + 1);
int ans = 0;
int cnt = 0;
for (i = 1; i <= n; i++) {
if (vis[i]) continue;
vis[i] = 1;
ans++;
cnt = 1;
for (j = i + 1; j <= n; j++) {
if (vis[j]) continue;
if (a[j] >= cnt) {
cnt++;
vis[j] = 1;
}
}
}
printf("%d\n", ans);
}
return 0;
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
vector<int> v1, v2;
int n, ctr, counter, flag;
cin >> n;
v1.resize(n);
v2.resize(n);
for (int i = 0; i < n; i++) {
cin >> v1[i];
v2[i] = 0;
}
sort(v1.begin(), v1.end());
counter = 0;
while (1) {
flag = 0;
for (int i = 0; i < n; i++) {
if (v2[i] == 0) {
flag = 1;
break;
}
}
if (flag == 0) break;
ctr = 0;
for (int i = 0; i < n; i++) {
if (v2[i] == 0 && v1[i] == 0 && ctr == 0) {
ctr++;
v2[i] = 1;
} else if (v2[i] == 0 && v1[i] >= ctr) {
ctr++;
v2[i] = 1;
}
}
if (ctr != 0) {
counter++;
}
}
cout << counter << endl;
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
# from math import *
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
import copy
import time
# import numpy as np
starttime = time.time()
# import numpy as np
mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def L(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]
try:
# sys.setrecursionlimit(int(pow(10,6)))
sys.stdin = open("input.txt", "r")
# sys.stdout = open("../output.txt", "w")
except:
pass
n=L()[0]
A=L()
A.sort()
ans=[[] for i in range(n)]
for i in range(n):
for j in range(n):
if len(ans[j])<=A[i]:
ans[j].append(A[i])
break
k=0
# print(ans)
for i in range(n):
if ans[i]==[]:
break
k+=1
print(k)
endtime = time.time()
# print(f"Runtime of the program is {endtime - starttime}")
| PYTHON3 |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | import sys
#input=sys.stdin.buffer.readline
t=1
mod=10**9+7
for __ in range(t):
#a=[]
n=int(input())
#n,m=map(int,input().split())
l=list(map(int,input().split()))
l.sort()
cnt=0
maxi=0
ans=0
# print(l)
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
#print(l)
ans+=1
print(ans)
| PYTHON3 |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | import java.io.*;
import java.util.*;
public class CFR2283 {
public static void main (String[] args) {
Scanner sc = new Scanner (System.in);
PrintStream op = System.out;
int N = sc.nextInt();
int[] X = new int [N];
int[] pile = new int [N];
for (int i = 0; i < N; i++)
X[i] = sc.nextInt();
Arrays.sort(X);
int loc = 1;
boolean isPresent = true;
while (isPresent) {
isPresent = false;
int i;
for (i = 0; i < N; i++) {
if (pile[i] == 0)
break;
}
pile[i] = loc;
i++;
int count = 1;
while (i < N) {
if (pile[i] == 0) {
if (X[i] >= count) {
pile[i] = loc;
count++;
}
else
isPresent = true;
}
i++;
}
loc++;
}
op.println(loc - 1);
sc.close();
}
} | JAVA |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const double PI = 2.0 * acos(0.0);
const double EPS = 1e-9;
int cases = 1;
double getdist(pair<int, int> a, pair<int, int> b) {
return sqrt(pow(a.first - b.first, 2) + pow(a.second - b.second, 2));
}
void read(void) { return; }
int n, box[105];
int main() {
int test;
while (scanf("%d", &n) == 1) {
for (int i = 0; i < n; ++i) scanf("%d", &box[i]);
sort(box, box + n);
int taken[105] = {0}, cnt = 0;
for (int i = 0; i < n; ++i) {
if (taken[i] != 0) continue;
cnt++;
taken[i] = 1;
int tola = 1;
for (int j = i + 1; j < n; ++j) {
if (taken[j] == 0 and tola <= box[j]) {
taken[j] = 1;
tola++;
}
}
}
cout << cnt << endl;
}
return 0;
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | 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)==00:
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)) | PYTHON3 |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase
#from bisect import bisect_left as bl #c++ lowerbound bl(array,element)
#from bisect import bisect_right as br #c++ upperbound br(array,element)
def main():
n=int(input())
a=list(map(int,input().split(" ")))
cnt=0
while len(a)!=0:
temp=list(a)
temp.sort()
x=0
while x<len(temp):
if temp[x]<x:
temp.pop(x)
else:
x+=1
cnt+=1
#print(temp)
for x in temp:
a.remove(x)
print(cnt)
#-----------------------------BOSS-------------------------------------!
# region fastio
BUFSIZE = 8192
class FastIO(IOBase):
newlines = 0
def __init__(self, file):
self._fd = file.fileno()
self.buffer = BytesIO()
self.writable = "x" in file.mode or "r" not in file.mode
self.write = self.buffer.write if self.writable else None
def read(self):
while True:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
if not b:
break
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines = 0
return self.buffer.read()
def readline(self):
while self.newlines == 0:
b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
self.newlines = b.count(b"\n") + (not b)
ptr = self.buffer.tell()
self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
self.newlines -= 1
return self.buffer.readline()
def flush(self):
if self.writable:
os.write(self._fd, self.buffer.getvalue())
self.buffer.truncate(0), self.buffer.seek(0)
class IOWrapper(IOBase):
def __init__(self, file):
self.buffer = FastIO(file)
self.flush = self.buffer.flush
self.writable = self.buffer.writable
self.write = lambda s: self.buffer.write(s.encode("ascii"))
self.read = lambda: self.buffer.read().decode("ascii")
self.readline = lambda: self.buffer.readline().decode("ascii")
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
main() | PYTHON3 |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | import java.io.*;
import java.math.*;
import java.util.*;
/**
*
* @author Saju
*
*/
public class Main {
private static int dx[] = { 1, 0, -1, 0 };
private static int dy[] = { 0, -1, 0, 1 };
private static final long INF = Long.MAX_VALUE;
private static final int INT_INF = Integer.MAX_VALUE;
private static final long NEG_INF = Long.MIN_VALUE;
private static final int NEG_INT_INF = Integer.MIN_VALUE;
private static final double EPSILON = 1e-10;
private static final int MAX = 2000007;
private static final long MOD = 1000000007;
private static final int MAXN = 100007;
private static final int MAXA = 10000009;
private static final int MAXLOG = 22;
public static void main(String[] args) throws IOException {
InputReader in = new InputReader(System.in);
// Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
// InputReader in = new InputReader(new FileInputStream("src/test.in"));
// PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("src/test.out")));
/*
*/
int n = in.nextInt();
int arr[] = in.nextIntArr(n);
Arrays.sort(arr);
int i = 0;
int piles = 0;
while(i != n) {
piles++;
int cnt = 0;
for(int j = 0; j < n; j++) {
if(arr[j] != -1) {
if(arr[j] >= cnt) {
cnt++;
arr[j] = -1;
}
}
}
i += cnt;
}
out.println(piles);
in.close();
out.flush();
out.close();
System.exit(0);
}
private static boolean isPalindrome(String str) {
StringBuilder sb = new StringBuilder();
sb.append(str);
String str1 = sb.reverse().toString();
return str.equals(str1);
}
private static String getBinaryStr(int n, int j) {
String str = Integer.toBinaryString(n);
int k = str.length();
for (int i = 1; i <= j - k; i++) {
str = "0" + str;
}
return str;
}
private static String getBinaryStr(long n, int j) {
String str = Long.toBinaryString(n);
int k = str.length();
for (int i = 1; i <= j - k; i++) {
str = "0" + str;
}
return str;
}
private static long bigMod(long n, long k, long m) {
long ans = 1;
while (k > 0) {
if ((k & 1) == 1) {
ans = (ans * n) % m;
}
n = (n * n) % m;
k >>= 1;
}
return ans;
}
private static long ceil(long n, long x) {
long div = n / x;
if(div * x != n) {
div++;
}
return div;
}
private static int ceil(int n, int x) {
int div = n / x;
if(div * x != n) {
div++;
}
return div;
}
private static class Point {
double x;
double y;
Point(double x, double y) {
this.x = x;
this.y = y;
}
double getDistance(Point p2) {
Point p1 = this;
double dx = p1.x - p2.x;
double dy = p1.y - p2.y;
return Math.sqrt((dx * dx) + (dy * dy));
}
}
private static int abs(int x) {
if (x < 0) {
return -x;
}
return x;
}
private static long abs(long x) {
if(x < 0) {
return -x;
}
return x;
}
private static int lcm(int a, int b) {
return (a * b) / gcd(a, b);
}
private static int gcd(int a, int b) {
if (a == 0)
return b;
return gcd(b % a, a);
}
private static int log(long x, int base) {
return (int) (Math.log(x) / Math.log(base));
}
private static long min(long a, long b) {
if (a < b) {
return a;
}
return b;
}
private static int min(int a, int b) {
if (a < b) {
return a;
}
return b;
}
private static long max(long a, long b) {
if (a < b) {
return b;
}
return a;
}
private static int max(int a, int b) {
if (a < b) {
return b;
}
return a;
}
private static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public String next() {
try {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
} catch (IOException e) {
return null;
}
return tokenizer.nextToken();
}
public String nextLine() {
String line = null;
try {
tokenizer = null;
line = reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
return line;
}
public int nextInt() {
return Integer.parseInt(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public boolean hasNext() {
try {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
} catch (Exception e) {
return false;
}
return true;
}
public int[] nextIntArr(int n) {
int arr[] = new int[n];
for(int i = 0; i < n; i++) {
arr[i] = nextInt();
}
return arr;
}
public long[] nextLongArr(int n) {
long arr[] = new long[n];
for(int i = 0; i < n; i++) {
arr[i] = nextLong();
}
return arr;
}
public int[] nextIntArr1(int n) {
int arr[] = new int[n + 1];
for(int i = 1; i <= n; i++) {
arr[i] = nextInt();
}
return arr;
}
public long[] nextLongArr1(int n) {
long arr[] = new long[n + 1];
for(int i = 1; i <= n; i++) {
arr[i] = nextLong();
}
return arr;
}
public void close() {
try {
if(reader != null) {
reader.close();
}
}
catch(Exception e) {
}
}
}
}
| JAVA |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int MAXN = 100 + 10;
int n, a[MAXN], mark[MAXN], l;
void input() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
}
int main() {
input();
int l = 0;
bool chek;
for (int i = 0; i < n; i++) {
chek = true;
for (int j = 0; j < l; j++) {
if (mark[j] <= a[i]) {
mark[j]++;
chek = false;
break;
}
}
if (chek == true) {
mark[l] = 1;
l++;
}
}
cout << l << endl;
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
Task solver = new Task();
solver.solve(1, in, out);
out.close();
}
}
class Task {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt();
int[] a = new int[n];
int[] vis = new int[n];
for (int i = 0; i < n; i++)
a[i] = in.nextInt();
Arrays.sort(a);
int ans = 0;
for (int i = n - 1; i >= 0; i--)
if (vis[i] == 0) {
ans++;
vis[i] = 1;
int hold = a[i];
while (hold != 0) {
int tmp = -1, k = -1;
for (int j = n - 1; j >= 0; j--)
if (vis[j] == 0) {
if (tmp <= Math.min(hold - 1, a[j])) {
tmp = Math.min(hold - 1, a[j]);
k = j;
}
}
if (k == -1) break;
hold = Math.min(hold - 1, a[k]);
vis[k] = 1;
}
}
out.println(ans);
}
}
class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream){
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDoubel() {
return Double.parseDouble(next());
}
}
| JAVA |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
int x[101];
int towers = 0;
int n;
cin >> n;
for (int i = 0; i < n; i++) cin >> x[i];
sort(x, x + n);
int count = 0;
while (count < n) {
int cur = 0;
for (int i = 0; i < n; i++) {
if (x[i] >= cur) {
count++;
cur++;
x[i] = -1;
}
}
towers++;
}
cout << towers << endl;
return 0;
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | import java.io.*;
import java.util.*;
/*
@author Mikhail Linkov
*/
public class TaskC {
private final static int MAX = 10000001;
public void solve() {
InputReader reader = new InputReader(System.in);
PrintWriter writer = new PrintWriter(System.out, true);
int n = reader.nextInt();
List<Integer> list = new ArrayList<Integer>();
boolean [] isUsed = new boolean[n];
for (int i = 0; i < n; i++) {
list.add(reader.nextInt());
}
Collections.sort(list);
Collections.reverse(list);
int [] min = new int[n];
for (int i = 1; i <= n; i++) {
boolean isCorrect = true;
for (int j = 0; j < n; j++) {
if (j < i) {
min[j] = list.get(j);
} else {
if (min[j % i] == 0) {
isCorrect = false;
break;
}
min[j % i] = Math.min(min[j % i] - 1, list.get(j));
}
}
if (isCorrect) {
writer.println(i);
break;
}
}
writer.close();
}
public static void main(String[] args) {
new TaskC().solve();
}
private class InputReader {
private BufferedReader reader;
private StringTokenizer token;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
}
public String next() {
if (token == null || !token.hasMoreElements()) {
try {
token = new StringTokenizer(reader.readLine(), " ");
} catch (Exception e) {
throw new RuntimeException();
}
}
return token.nextToken();
}
public int nextInt() {
return Integer.parseInt(this.next());
}
public double nextDouble() {
return Double.parseDouble(this.next());
}
public long nextLong() {
return Long.parseLong(this.next());
}
public String nextLine() {
try {
return reader.readLine();
} catch (Exception e) {
throw new RuntimeException();
}
}
}
}
| JAVA |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | /*
Keep solving problems.
*/
import java.util.*;
import java.io.*;
public class CFA {
BufferedReader br;
PrintWriter out;
StringTokenizer st;
boolean eof;
final long MOD = 1000L * 1000L * 1000L + 7;
int[] dx = {0, -1, 0, 1};
int[] dy = {1, 0, -1, 0};
void solve() throws IOException {
int n = nextInt();
int[] arr = nextIntArr(n);
int m = 100;
int[] hist = new int[m + 1];
for (int v : arr) {
hist[v]++;
}
int res = 0;
while (true) {
int id = -1;
for (int i = 0; i <= m; i++) {
if (hist[i] != 0) {
id = i;
break;
}
}
if (id == -1) {
break;
}
int cnt = 0;
int i = id;
while (i <= m) {
if (hist[i] != 0) {
cnt++;
hist[i]--;
i = Math.max(cnt, i);
}
else {
i++;
}
}
res++;
}
out(res);
}
void shuffle(int[] a) {
int n = a.length;
for(int i = 0; i < n; i++) {
int r = i + (int) (Math.random() * (n - i));
int tmp = a[i];
a[i] = a[r];
a[r] = tmp;
}
}
long gcd(long a, long b) {
while(a != 0 && b != 0) {
long c = b;
b = a % b;
a = c;
}
return a + b;
}
private void outln(Object o) {
out.println(o);
}
private void out(Object o) {
out.print(o);
}
public CFA() throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
solve();
out.close();
}
public static void main(String[] args) throws IOException {
new CFA();
}
public long[] nextLongArr(int n) throws IOException{
long[] res = new long[n];
for(int i = 0; i < n; i++)
res[i] = nextLong();
return res;
}
public int[] nextIntArr(int n) throws IOException {
int[] res = new int[n];
for(int i = 0; i < n; i++)
res[i] = nextInt();
return res;
}
public String nextToken() {
while (st == null || !st.hasMoreTokens()) {
try {
st = new StringTokenizer(br.readLine());
} catch (Exception e) {
eof = true;
return null;
}
}
return st.nextToken();
}
public String nextString() {
try {
return br.readLine();
} catch (IOException e) {
eof = true;
return null;
}
}
public int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
public long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
public double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
}
| JAVA |
389_C. Fox and Box Accumulation | 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> | 2 | 9 |
n=int(input())
a=list(map(int,input().split()))
a.sort()
visited=[0]*n
i=0
res=0
while i<n:
if visited[i]==0:
visited[i]=0
j=i
c=0
while j<n:
if a[j]>=c and visited[j]==0:
visited[j]=1
c += 1
j+=1
res+=1
i += 1
print(res)
| PYTHON3 |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int piles[105];
int main() {
int n;
cin >> n;
vector<int> A(n);
for (int i = 0; i < n; ++i) cin >> A[i];
sort(A.begin(), A.end());
for (int i = 0; i < n; ++i) {
bool flag = false;
for (int j = 0; j <= A[i]; ++j)
if (piles[j]) {
--piles[j];
++piles[j + 1];
flag = true;
break;
}
if (!flag) piles[1] += 1;
}
int cnt = 0;
for (int i = 1; i < 105; ++i) cnt += piles[i];
cout << cnt;
return 0;
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int mm[105] = {0};
bool vis[105] = {0};
int main() {
int n, ans = 0, m;
cin >> n;
m = n;
for (int i = 0; i < n; i++) {
cin >> mm[i];
}
sort(mm, mm + n);
int we = 0;
while (m) {
for (int i = 0; i < n; i++) {
if (!vis[i] && mm[i] >= we) {
vis[i] = 1;
we++;
m--;
}
}
ans++;
we = 0;
}
cout << ans << endl;
return 0;
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | # import sys
# sys.stdin = open('input.txt', 'r')
# sys.stdout = open('output.txt', 'w')
# t=int(input())
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) | PYTHON3 |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | import java.io.*;
import java.lang.reflect.Array;
import java.math.*;
import java.text.DecimalFormat;
import java.util.*;
public class Main {
private static int n;
private static int [] A;
private static boolean can(int m) {
int [] R = new int[m];
for (int i = 0;i < m;i++)
R[i] = Integer.MAX_VALUE;
for (int i = 0;i < n;i += m){
for (int j = 0;j < m && i + j < n;j++) {
int t = i + j;
if (R[j] > 0)
R[j] = Math.min(R[j]-1,A[t]);
else
return false;
}
}
return true;
}
public static void main(String[] args) throws Exception {
IO io = new IO(null,null);
n = io.getNextInt();
A = new int[n];
for (int i = 0;i < n;i++)
A[i] = io.getNextInt();
Arrays.sort(A);
for (int i = 0;2*i < n;i++){
int t = A[i];
A[i] = A[n-1-i];
A[n-1-i] = t;
}
int s = 1,e = n;
while (s < e) {
int m = (s + e) >> 1;
if (can(m)) e = m;
else s = m+1;
}
io.println(s);
io.close();
}
}
class IO{
private BufferedReader br;
private StringTokenizer st;
private PrintWriter writer;
private String inputFile,outputFile;
public boolean hasMore() throws IOException{
if(st != null && st.hasMoreTokens()) return true;
if(br != null && br.ready()) return true;
return false;
}
public String getNext() throws FileNotFoundException, IOException{
while(st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine());
return st.nextToken();
}
public String getNextLine() throws FileNotFoundException, IOException{
return br.readLine().trim();
}
public int getNextInt() throws FileNotFoundException, IOException{
return Integer.parseInt(getNext());
}
public long getNextLong() throws FileNotFoundException, IOException{
return Long.parseLong(getNext());
}
public void print(double x,int num_digits) throws IOException{
writer.printf("%." + num_digits + "f" ,x);
}
public void println(double x,int num_digits) throws IOException{
writer.printf("%." + num_digits + "f\n" ,x);
}
public void print(Object o) throws IOException{
writer.print(o.toString());
}
public void println(Object o) throws IOException{
writer.println(o.toString());
}
public IO(String x,String y) throws FileNotFoundException, IOException{
inputFile = x;
outputFile = y;
if(x != null) br = new BufferedReader(new FileReader(inputFile));
else br = new BufferedReader(new InputStreamReader(System.in));
if(y != null) writer = new PrintWriter(new BufferedWriter(new FileWriter(outputFile)));
else writer = new PrintWriter(new OutputStreamWriter(System.out));
}
protected void close() throws IOException{
br.close();
writer.close();
}
public void outputArr(Object [] A) throws IOException{
int L = A.length;
for (int i = 0;i < L;i++) {
if(i > 0) writer.print(" ");
writer.print(A[i]);
}
writer.print("\n");
}
}
| JAVA |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | def main():
mode="filee"
if mode=="file":f=open("test.txt","r")
#f.readline()
#input()
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()
if __name__=="__main__":
main()
| PYTHON3 |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | import java.util.ArrayList;
import java.util.Comparator;
import java.util.Iterator;
import java.util.Scanner;
/**
* Created by PalmZE on 13.11.2015.
*/
public class Task388A {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
int n = scanner.nextInt();
ArrayList<Integer> durability = new ArrayList<Integer>();
for (int i = 0; i < n; i++) {
durability.add(scanner.nextInt());
}
int counter = 0;
boolean first = true;
durability.sort(Comparator.reverseOrder());
//System.out.println(durability);
ArrayList<Integer> search = new ArrayList<Integer>();
ArrayList<Integer> searchD = new ArrayList<Integer>();
while (!durability.isEmpty()) {
if (straight(durability)) {counter++; break;}
Iterator<Integer> itr = durability.iterator();
while (!searchD.contains(0) && itr.hasNext()) {
int curr = itr.next();
if (first) {
search.add(curr);
searchD.add(curr);
itr.remove();
first = false;
}
else if (curr < search.get(search.size()-1)) {
for (int i = 0; i< search.size(); i++) searchD.set(i, searchD.get(i) - 1);
search.add(curr);
searchD.add(curr);
itr.remove();
}
else if (curr >= search.get(search.size()-1)) {
while (itr.hasNext() && curr>=search.get(search.size()-1)) {
curr = itr.next();
}
for (int i = 0; i< search.size(); i++) searchD.set(i, searchD.get(i) - 1);
search.add(curr);
searchD.add(curr);
itr.remove();
itr = durability.iterator();
}//System.out.println("searchD" + searchD);
}
for (Integer i = search.get(0); i < 101; i++) {
if (durability.contains(i) && i>=search.size()) {
search.add(i);
durability.remove(i);
}
}
counter++;
first = true;
//System.out.println(search);
search.clear();
searchD.clear();
//System.out.println("Durability" + durability);
}
System.out.println(counter);
}
public static boolean straight(ArrayList<Integer> dur) {
boolean str = true;
for (int i = 0; i < dur.size()-1; i++) {
if ((dur.get(i) - dur.size() + (i + 1)) < 0) {str=false; break;}
}
return str;
}
}
| JAVA |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | n,ans,tot=input(),0,0
a=sorted(map(int, raw_input().split()))
taken = [False] * n
while tot < n:
curr=0
for i in range(n):
if (not taken[i]) and a[i] >= curr:
taken[i] = True
curr += 1
tot += curr
ans += 1
print ans
| PYTHON |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int N = 200;
int a[N];
bool used[N];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
sort(a, a + n);
int cnt = 0;
int ans = 0;
while (cnt != n) {
int st = 0;
for (int i = 0; i < n; i++) {
if (!used[i]) {
st = i;
break;
}
}
int curW = 1;
used[st] = 1;
cnt++;
ans++;
for (int i = st + 1; i < n; i++) {
if (!used[i] && a[i] >= curW) {
used[i] = 1;
curW++;
cnt++;
}
}
}
printf("%d", ans);
return 0;
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
int H[101] = {0};
int n, x;
cin >> n;
for (int i = 0; i < n; i++) cin >> x, H[x]++;
int ats = 0;
int box = 0;
while (box <= 100) {
if (H[box] == 0) {
box++;
continue;
}
ats++;
H[box]--;
int boxes = 1;
for (int j = box; j <= 100; j++)
while (H[j] > 0 && j >= boxes) H[j]--, boxes++;
}
cout << ats;
return 0;
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.util.Arrays;
import java.util.Comparator;
import java.util.StringTokenizer;
public class Main
{
private static BufferedWriter out;
private static int n;
private static Integer[] arr;
public static void main(String[] args) throws IOException
{
// The input and output streams
boolean file = false;
BufferedReader in;
if (file)
in = new BufferedReader(new FileReader("input.txt"), 32768);
else
in = new BufferedReader(new InputStreamReader(System.in), 32768);
out = new BufferedWriter(new OutputStreamWriter(System.out));
StringTokenizer tok;
// take input
n= Integer.parseInt(in.readLine());
tok = new StringTokenizer(in.readLine());
arr = new Integer[n];
for (int i = 0; i < n; i++)
arr[i] = Integer.parseInt(tok.nextToken());
Arrays.sort(arr, new Comparator<Integer>()
{
@Override
public int compare(Integer o1, Integer o2)
{
return Integer.compare(o2, o1);
}
});
// binary search for the answer
int min = 1;
int max = n;
while (min <= max)
{
int mid = (min + max) / 2;
if (valid(mid) && !valid(mid - 1))
{
System.out.println(mid);
return;
}
else if (valid(mid))
max = mid - 1;
else
min = mid + 1;
}
int x = 1 / 0;
}
private static boolean valid(int p)
{
int[] piles = new int[p];
for (int i = 0; i < p; i++)
piles[i] = Integer.MAX_VALUE;
int curr = 0;
while(true)
{
boolean found = false;
for (int i = 0; i < p && curr< n; i++)
{
if (piles[i] > 0)
{
piles[i] = Math.min(piles[i]-1, arr[curr]);
curr ++;
found = true;
}
}
if (!found)
break;
}
return curr == n;
}
} | JAVA |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int n;
int x[110];
multiset<int, greater<int> > s;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &x[i]);
sort(x, x + n);
for (int i = 0; i < n; i++) {
auto y = s.lower_bound(x[i]);
if (y == s.end()) {
s.insert(1);
} else {
int t = *y;
s.erase(y);
s.insert(t + 1);
}
}
printf("%d", s.size());
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | 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)
| PYTHON3 |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class T389C {
public void solve(int n, int[] x) {
Arrays.sort(x);
int cur = 0;
int ans = 0;
int cnt = n;
boolean[] f = new boolean[n];
while(cnt > 0) {
ans ++;
cur = 0;
for(int i = 0; i < n;i ++) {
if(x[i] >= cur && !f[i]) {
cur ++;
cnt --;
f[i] = true;
}
}
}
System.out.println(ans);
}
public static void main(String[] args) {
FastScanner in = new FastScanner();
int n = in.nextInt();
int[] x = new int[n];
for (int i = 0; i < n; i ++)
x[i] = in.nextInt();
new T389C().solve(n, x);
}
static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(String s) {
try {
br = new BufferedReader(new FileReader(s));
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
public FastScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String nextToken() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(nextToken());
}
long nextLong() {
return Long.parseLong(nextToken());
}
double nextDouble() {
return Double.parseDouble(nextToken());
}
}
}
| JAVA |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | //https://codeforces.com/problemset/problem/388/A
//A. Fox and Box Accumulation
import java.util.*;
import java.io.*;
public class CF_388_A{
public static void main(String[] args) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(new OutputStreamWriter(System.out));
StringTokenizer st;
int n = Integer.parseInt(br.readLine());
int a[] = new int[n];
st = new StringTokenizer(br.readLine());
for(int i=0;i<n;i++)
a[i] = Integer.parseInt(st.nextToken());
Arrays.sort(a);
int no_of_heaps = 1;
for(int i=1;i<n;i++){
int min_size_of_heap = i/no_of_heaps;
if(a[i]<min_size_of_heap)
no_of_heaps++;
}
pw.print(no_of_heaps);
pw.flush();
pw.close();
}
} | JAVA |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 111;
int n, ans;
int a[maxn];
bool v[maxn];
void Init() {
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
}
void Work() {
sort(a + 1, a + 1 + n);
while (1) {
int pos = 1;
while (v[pos] && pos <= n) pos++;
if (pos == n + 1) break;
v[pos] = 1;
int len = 1;
while (pos <= n) {
if (a[pos] < len || v[pos]) {
pos++;
continue;
}
v[pos] = 1;
len++;
pos++;
}
ans++;
}
printf("%d\n", ans);
}
int main() {
Init();
Work();
return 0;
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int N = 109;
int a[N], c[N];
int main() {
int n;
scanf("%d", &n);
for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
sort(a, a + n);
reverse(a, a + n);
int ans = -1;
for (int i = 1; i <= n; ++i) {
memset(c, 0, sizeof(c));
for (int j = 0; j < i; ++j) c[j] = a[j];
bool ok = 1;
for (int j = i; j < n; ++j) {
j % i;
a[j];
if (c[j % i] > 0) {
c[j % i] = min(c[j % i] - 1, a[j]);
} else {
ok = 0;
break;
}
}
if (ok) {
ans = i;
break;
}
}
cout << ans << endl;
return 0;
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | import java.util.*;
public class c228
{
public static void main(String ar[])
{
Scanner obj=new Scanner(System.in);
int n=obj.nextInt();
int a[]=new int[n];
boolean b[]=new boolean[n];
Arrays.fill(b,false);
for(int i=0;i<n;i++)
a[i]=obj.nextInt();
Arrays.sort(a);
int cnt=n;
int ret=0;
int cur=0;
while(cnt>0)
{
ret+=1;
cur=0;
for(int i=0;i<n;i++)
{
if(a[i]>=cur&&b[i]==false)
{
cur+=1;
cnt-=1;
b[i]=true;
}
}
}
System.out.println(ret);
}
}
| JAVA |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int n, x[105], used[105], ans = 0;
int main() {
cin >> n;
for (int i = 0; i < n; i++) cin >> x[i];
sort(x, x + n);
for (int i = 0; i < n; i++) {
if (!used[i]) {
used[i] = 1;
int l = 1;
for (int j = i + 1; j < n; j++) {
if (!used[j] && l <= x[j]) {
used[j] = 1;
l++;
}
}
ans++;
}
}
cout << ans;
return 0;
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | 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 | PYTHON3 |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int arr[101];
int main() {
int i, j, n, ans = 0, size = 0;
scanf("%d", &n);
int b[n];
for (i = 0; i < n; i++) {
scanf("%d", &b[i]);
arr[b[i]]++;
}
for (i = 0; i <= 100; i++) {
size = 0;
if (arr[i] > 0) {
ans++;
arr[i]--;
size++;
for (j = size; j <= 100; j++) {
if (arr[j] > 0) {
arr[j]--;
size++;
j = size - 1;
}
}
}
if (arr[i] > 0) i--;
}
cout << ans << endl;
return 0;
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | import java.io.IOException;
import java.util.Arrays;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author Mahmoud Aladdin <aladdin3>
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskC solver = new TaskC();
solver.solve(1, in, out);
out.close();
}
}
class TaskC {
private static final int INF = Integer.MAX_VALUE;
public void solve(int testNumber, InputReader jin, PrintWriter jout) {
int n = jin.int32();
int[] crates = new int[n];
for(int i = 0; i < n; i++) {
crates[i] = jin.int32();
}
Arrays.sort(crates);
int cj = 0;
int[] piles = new int[n];
for(int ci = 1; ci <= n; ci++) {
int count = n; cj = 0;
Arrays.fill(piles, INF);
for(int i = crates.length - 1; i >= 0; i--) {
for(int j = 0; j < ci; j++) {
if(piles[(cj + j) % ci] > 0) {
piles[(cj + j) % ci] = Math.min(piles[(cj + j) % ci] - 1, crates[i]);
count--;
cj = (cj + j + 1) % ci;
break;
}
cj = (cj + j) % ci;
}
}
if(count == 0) {
jout.println(ci);
return;
}
}
}
}
class InputReader {
private static final int bufferMaxLength = 1024;
private InputStream in;
private byte[] buffer;
private int currentBufferSize;
private int currentBufferTop;
private static final String tokenizers = " \t\r\f\n";
public InputReader(InputStream stream) {
this.in = stream;
buffer = new byte[bufferMaxLength];
currentBufferSize = 0;
currentBufferTop = 0;
}
private boolean refill() {
try {
this.currentBufferSize = this.in.read(this.buffer);
this.currentBufferTop = 0;
} catch(Exception e) {}
return this.currentBufferSize > 0;
}
private Byte readChar() {
if(currentBufferTop < currentBufferSize) {
return this.buffer[this.currentBufferTop++];
} else {
if(!this.refill()) {
return null;
} else {
return readChar();
}
}
}
public String token() {
StringBuffer tok = new StringBuffer();
Byte first;
while((first = readChar()) != null && (tokenizers.indexOf((char) first.byteValue()) != -1));
if(first == null) return null;
tok.append((char)first.byteValue());
while((first = readChar()) != null && (tokenizers.indexOf((char) first.byteValue()) == -1)) {
tok.append((char)first.byteValue());
}
return tok.toString();
}
public Integer int32() throws NumberFormatException {
String tok = token();
return tok == null? null : Integer.parseInt(tok);
}
}
| JAVA |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | import java.util.Scanner;
import java.io.OutputStream;
import java.io.IOException;
import java.util.Arrays;
import java.io.PrintWriter;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author Himalay([email protected])
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
Scanner in = new Scanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskC solver = new TaskC();
solver.solve(1, in, out);
out.close();
}
}
class TaskC {
int n;
Integer arr[];
public void solve(int testNumber, Scanner in, PrintWriter out) {
n = in.nextInt();
arr = new Integer[n];
for (int i = 0; i < n;i++) {
arr[i] = in.nextInt();
}
Arrays.sort(arr);
for (int ans = 1; ans <= n; ans++) {
if (func(ans)) {
out.println(ans);
return;
}
}
return;
}
private boolean func(int ans) {
int cap[] = new int[ans];
for (int i = 0; i < ans; i++) {
cap[i] = Integer.MAX_VALUE;
}
int next = 0;
for (int i = n-1; i > -1; i--) {
if (cap[next] > arr[i]) {
cap[next] = arr[i];
}else if (cap[next] != 0) {
cap[next]--;
}else
return false;
next = (next + 1) % ans;
}
return true;
}
}
| JAVA |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | 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)
| PYTHON3 |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | n,ans = input(),0
a = map(int,raw_input().split())
h = [(len(filter(lambda x:x <= i,a))+i)/(i+1) for i in range(101)]
print max(h)
| PYTHON |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int n;
int a[110], d[110];
void solve() {
int i, j, ans, con, dem;
memset(d, 0, sizeof(d));
sort(a, a + n);
ans = 0;
con = n;
while (con) {
dem = 0;
for (i = 0; i < n; i++)
if (d[i] == 0 && a[i] >= dem) {
d[i] = 1;
dem++;
con--;
}
ans++;
}
printf("%d\n", ans);
}
void input() {
int i;
scanf("%d", &n);
for (i = 0; i < n; i++) scanf("%d", &a[i]);
solve();
}
int main() {
input();
fclose(stdin);
fclose(stdout);
return 0;
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
int n, ans = 0;
cin >> n;
vector<int> a(n), c(n, 1), p(n, -1);
for (int i = 0; i < n; i++) cin >> a[i];
sort(a.begin(), a.end());
while (a.size()) {
fill(c.begin(), c.begin() + a.size(), 1);
fill(p.begin(), p.begin() + a.size(), -1);
for (int i = 1; i < a.size(); i++) {
for (int j = 0; j < i; j++) {
if (a[i] >= c[j]) {
if (c[j] + 1 > c[i]) {
c[i] = c[j] + 1;
p[i] = j;
}
}
}
}
int k = max_element(c.begin(), c.begin() + a.size()) - c.begin();
while (k != -1) {
a.erase(a.begin() + k);
k = p[k];
}
ans++;
}
cout << ans;
return 0;
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const long double eps = 1e-9;
const int inf = (1 << 30) - 1;
const long long inf64 = ((long long)1 << 62) - 1;
const long double pi = 3.1415926535897932384626433832795;
template <class T>
T sqr(T x) {
return x * x;
}
template <class T>
T abs(T x) {
return x < 0 ? -x : x;
}
const int MAXN = 120;
int a[MAXN], sum[MAXN];
int main() {
ios_base::sync_with_stdio(0);
int n;
cin >> n;
int x;
for (int i = 0; i < n; ++i) {
cin >> x;
a[x]++;
}
sum[0] = a[0];
for (int i = 1; i < MAXN; ++i) {
sum[i] = sum[i - 1] + a[i];
}
int ans = 0;
for (int i = 0; i < MAXN; ++i) {
ans = max(ans, (sum[i] + i) / (i + 1));
}
cout << ans << endl;
return 0;
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;
public class A {
public static void main(String[] args) throws Exception{
int n = readInt();
int[] t = new int[n];
for(int i = 0; i < n; i++){
t[i] = readInt();
}
Arrays.sort(t);
int piles = 0;
boolean found = true;
while(found){
int count = 0;
found = false;
for(int i = 0; i<n; i++){
if(t[i] != -1 && !found){
found = true;
piles++;
}
if(t[i] >= count){
count++;
t[i] = -1;
}
}
}
System.out.println(piles);
}
static BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer st = new StringTokenizer(" ");
static String readString() throws Exception{
while(!st.hasMoreTokens()){
st = new StringTokenizer(stdin.readLine());
}
return st.nextToken();
}
static int readInt() throws Exception {
return Integer.parseInt(readString());
}
static long readLong() throws Exception {
return Long.parseLong(readString());
}
}
| JAVA |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
import java.util.Scanner;
public class round389problemc {
static Scanner in = new Scanner(System.in);
public static void main(String[] args) {
int n=in.nextInt();
ArrayList<Integer> a=new ArrayList<Integer>();
for(int i=0;i<n;i++){
a.add(in.nextInt());
}
Collections.sort(a);
System.out.println(makePile(a));
}
public static int makePile(ArrayList<Integer> list){
if(list.size()==0) return 0;
int p=1;
list.remove(0);
Iterator<Integer> i=list.iterator();
while(i.hasNext()){
if(i.next()>=p){p++;i.remove();}
}
return 1+makePile(list);
}
}
| JAVA |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | import java.io.*;
import java.util.*;
public class CodeForces {
public void solve() throws IOException {
int n = nextInt();
List<Integer> arr = new ArrayList<Integer>();
int res = 0;
for (int i = 0; i < n; i++) {
arr.add(nextInt());
}
Collections.sort(arr);
while (arr.size() > 0) {
int h = 0;
List<Integer> tarr = new ArrayList<Integer>();
for (int i = 0, l = arr.size(); i < l; i++) {
if (arr.get(i) >= h) {
h++;
} else {
tarr.add(arr.get(i));
}
}
res++;
arr = tarr;
}
System.out.println(res);
}
public static void main(String[] args) {
new CodeForces().run();
}
int NOD(int a, int b) {
while (a != 0 && b != 0) {
if (a >= b)
a = a % b;
else
b = b % a;
}
return a + b;
}
BufferedReader reader;
StringTokenizer tokenizer;
PrintWriter out;
boolean isOuterFile = false;
public void run() {
try {
if (isOuterFile) {
reader = new BufferedReader(new FileReader(
"C:\\work\\javaprojects\\CodeForces\\SCC.txt"));
// out = new PrintWriter(new BufferedWriter(new FileWriter(
// "output.txt")));
// out = new PrintWriter(System.out);
} else {
reader = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
}
tokenizer = null;
// long time = new Date().getTime();
solve();
// out.println(time - new Date().getTime());
reader.close();
out.close();
} catch (Exception e) {
e.printStackTrace();
System.exit(1);
}
}
int nextInt() throws IOException {
return Integer.parseInt(nextToken());
}
long nextLong() throws IOException {
return Long.parseLong(nextToken());
}
double nextDouble() throws IOException {
return Double.parseDouble(nextToken());
}
String nextToken() throws IOException {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(reader.readLine());
}
return tokenizer.nextToken();
}
} | JAVA |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int i, j, k, n, ans, used;
int main() {
cin >> n;
int a[n];
for (i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
while (used < n) {
ans++;
k = 0;
for (i = 0; i < n; i++)
if (a[i] >= k) {
a[i] = -1;
k++;
used++;
}
}
cout << ans;
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | n=int(raw_input())
l=map(int,raw_input().split())
ans=chk=cnt=0
l.sort()
while n:
if n==chk:
chk=0
cnt=0
if cnt==0:
ans+=1
l.pop(0)
cnt+=1
n-=1
elif cnt<=l[chk]:
l.pop(chk)
cnt+=1
n-=1
else:
chk+=1
print ans | PYTHON |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | def correct(a):
n = len(a)
for i in range(n):
for j in range(len(a[i])):
if (a[i][j] < len(a[i]) - j - 1):
return False
return True
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)
ans = n
for i in range(n, 0, -1):
cur = []
for j in range(i):
cur.append([])
for j in range(n):
cur[j % i].append(a[j])
#print(cur)
if (correct(cur)):
ans = i
print(ans) | PYTHON3 |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | import java.util.Scanner;
import java.util.TreeMap;
public class C228 {
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
int n = s.nextInt();
int[] w = new int[101];
for(int i = 0; i < n; i++)
w[s.nextInt()]++;
int ans = 0; int cov = 0;
int r = 100; int l = 0; int t = 0;
while(cov < n) {
r = 100; l = 0;
while(r > 0 && w[r] == 0) r--;
w[r]--; cov++; t = 0;
while(l < 101 && cov < n && r > 0) {
while(l < r && w[l] == 0) l++;
while(cov < n && r > 0 && t <= l && w[l] > 0) {
w[l]--; t++; r--; cov++;
}
l++;
}
ans++;
}
System.out.println(ans);
}
}
| JAVA |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios_base::sync_with_stdio(false);
long n, i, j, x = 0, ans = 0, term = 0;
long a[101];
bool vis[101] = {};
cin >> n;
for (i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
while (x < n) {
ans++, term = 0;
for (i = 0; i < n; i++)
if (!vis[i] && a[i] >= term) term++, vis[i] = true, x++;
}
cout << ans;
return 0;
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | N = input()
a = map(int, raw_input().split())
a.sort()
p = [1]
for x in a[1:]:
mini = min(p)
if x >= mini:
p[p.index(mini)] += 1
else:
p.append(1)
print len(p)
| PYTHON |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | 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)
| PYTHON3 |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeMap;
public class C {
static BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer st = new StringTokenizer("");
static String readString() throws Exception {
while(!st.hasMoreTokens())
st = new StringTokenizer(stdin.readLine());
return st.nextToken();
}
static int readInt() throws Exception {
return Integer.parseInt(readString());
}
public static void main(String[] args) throws Exception {
int n = readInt();
int x[] = new int[n];
PriorityQueue<Integer> pq = new PriorityQueue();
for(int i = 0; i < n; i++){
x[i] = readInt();
pq.add(x[i]);
}
int antallIPile = 0;
int piles = 0;
while(!pq.isEmpty()){
if(antallIPile == 0){
piles++;
antallIPile++;
int el = pq.poll();
}
PriorityQueue<Integer> t = new PriorityQueue();
while(!pq.isEmpty() && pq.peek() < antallIPile) t.add(pq.poll());
if(!pq.isEmpty()){
antallIPile++;
pq.poll();
while(!pq.isEmpty())t.add(pq.poll());
} else{
antallIPile = 0;
}
pq = t;
}
System.out.println(piles);
// Arrays.sort(x);
// int num = 0;
// boolean used[] = new boolean[n];
// for(int i = n-1; i >= 0; i--){
// if(used[i]) continue;
// int pile = x[i];
// System.out.println("new pile: "+pile);
// num++;
// int k = i-1;
// while(k >= 0){
// if(!used[k] && x[k] <= pile-1){
// pile = Math.min(pile-1, x[k]);
// used[k] = true;
// System.out.println("putting "+x[k]);
// }
// k -= 1;
// }
// if(pile > 0){
// for(int j = 0; j < n; j++){
// if(!used[j]){
// pile = Math.min(pile-1, x[j]);
// System.out.println("putting "+x[j]);
// used[j] = true;
// }
// if(pile == 0) break;
// }
// }
//
// }
// System.out.println(num);
//
// TreeMap<Integer, Integer> set = new TreeMap();
// for(int i = 0; i < n; i++){
// int el = readInt();
// if(set.containsKey(el)){
// set.put(el, set.get(el)+1);
// } else {
// set.put(el, 1);
// }
// }
//
// ArrayList<Integer> piles = new ArrayList();
// int last = set.lastKey();
// piles.add(last);
// if(set.get(last) == 1){
// set.remove(last);
// } else {
// set.put(last, set.get(last)-1);
// }
// while(!set.isEmpty()){
// boolean found = false;
// for(int i = 0; i < piles.size(); i++){
// int pile = piles.get(i);
// if(pile == 0) continue;
// Integer el = set.floorKey(pile-1);
// if(el == null){
// el = set.ceilingKey(pile);
// }
// piles.set(i, Math.min(pile-1, el));
// //System.out.println("putting on "+el);
// if(set.get(el) == 1){
// set.remove(el);
// } else {
// set.put(el, set.get(el)-1);
// }
// found = true;
// }
// if(!found){
// last = set.lastKey();
// piles.add(last);
// if(set.get(last) == 1){
// set.remove(last);
// } else {
// set.put(last, set.get(last)-1);
// }
// //System.out.println("new pile: "+piles.get(piles.size()-1));
// }
// }
// System.out.println(piles.size());
}
}
| JAVA |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int N;
int C[101];
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
int x;
cin >> x;
C[x]++;
}
int k = 0;
while (true) {
bool f = false;
int c = -1;
for (int x = 100; x >= 0; x--) {
if (C[x] > 0) {
C[x]--;
c = x;
break;
}
}
if (c == -1) break;
int t = 0;
while (t < c) {
bool f = false;
for (int x = t; x <= 100; x++) {
if (C[x] > 0) {
C[x]--;
t++;
f = true;
break;
}
}
if (!f) break;
}
k++;
}
cout << k << "\n";
return 0;
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int N = 4000009;
int main() {
int n;
cin >> n;
int a[111];
int x, ans = 0;
int xep[111] = {0};
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i++) {
x = 0;
if (!xep[i]) {
x++;
ans++;
for (int j = i + 1; j <= n; j++) {
if (!xep[j] && a[j] >= x) {
x++;
xep[j] = 1;
}
}
}
xep[i] = 1;
}
cout << ans;
return 0;
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int n, a[200];
int dp[200];
int main() {
cin >> n;
for (int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
dp[0] = 1;
for (int i = 1; i < n; i++) {
int ma = -1, v = -1;
for (int j = 0; j < i; j++)
if (dp[j] <= a[i] && dp[j] > ma) ma = dp[j], v = j;
if (ma == -1)
dp[i] = 1;
else {
dp[v]++;
dp[i] = 0;
}
}
int ans = 0;
for (int i = 0; i < n; i++)
if (dp[i] > 0) ans++;
cout << ans;
return 0;
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | import java.io.*;
import java.math.BigInteger;
import java.util.*;
import java.text.*;
public class cf389c {
static BufferedReader br;
static Scanner sc;
static PrintWriter out;
public static void initA() {
try {
br = new BufferedReader(new InputStreamReader(System.in));
sc = new Scanner(System.in);
out = new PrintWriter(System.out);
} catch (Exception e) {
}
}
static boolean next_permutation(Integer[] p) {
for (int a = p.length - 2; a >= 0; --a) {
if (p[a] < p[a + 1]) {
for (int b = p.length - 1;; --b) {
if (p[b] > p[a]) {
int t = p[a];
p[a] = p[b];
p[b] = t;
for (++a, b = p.length - 1; a < b; ++a, --b) {
t = p[a];
p[a] = p[b];
p[b] = t;
}
return true;
}
}
}
}
return false;
}
public static String getString() {
try {
return br.readLine();
} catch (Exception e) {
}
return "";
}
public static Integer getInt() {
try {
return Integer.parseInt(br.readLine());
} catch (Exception e) {
}
return 0;
}
public static Integer[] getIntArr() {
try {
StringTokenizer temp = new StringTokenizer(br.readLine());
int n = temp.countTokens();
Integer temp2[] = new Integer[n];
for (int i = 0; i < n; i++) {
temp2[i] = Integer.parseInt(temp.nextToken());
}
return temp2;
} catch (Exception e) {
}
return null;
}
public static Long[] getLongArr() {
try {
StringTokenizer temp = new StringTokenizer(br.readLine());
int n = temp.countTokens();
Long temp2[] = new Long[n];
for (int i = 0; i < n; i++) {
temp2[i] = Long.parseLong(temp.nextToken());
}
return temp2;
} catch (Exception e) {
}
return null;
}
public static String[] getStringArr() {
try {
StringTokenizer temp = new StringTokenizer(br.readLine());
int n = temp.countTokens();
String temp2[] = new String[n];
for (int i = 0; i < n; i++) {
temp2[i] = (temp.nextToken());
}
return temp2;
} catch (Exception e) {
}
return null;
}
public static void print(Object a) {
out.println(a);
}
public static void print(String s, Object... a) {
out.printf(s, a);
}
public static int nextInt() {
return sc.nextInt();
}
public static double nextDouble() {
return sc.nextDouble();
}
public static void main(String[] ar) {
initA();
solve();
out.flush();
}
private static class Point implements Comparable<Point>{
int x,y;
Point(int a, int b){
x= a;
y = b;
}
@Override
public int compareTo(Point o) {
if(x!=o.x){
return x-o.x;
}
return y - o.y;
}
public String toString(){
return x+",jml="+y;
}
}
public static void solve() {
int n = getInt();
Integer data[] = getIntArr();
Arrays.sort(data);
LinkedList<Point> temp = new LinkedList<Point>();
for (int i = 0; i < n; i++) {
Point t = new Point(data[i], 1);
temp.add(t);
}
int ou = 0;
while (!temp.isEmpty()) {
//print(temp);
Point t = temp.removeFirst();
boolean ada = false;
int ukuran = t.y;
for (Point p : temp) {
if (p.x >= ukuran) {
// print("GABUNG "+t+" dengan "+p);
p.x = Math.min(t.x, p.x-ukuran);
p.y = ukuran + p.y;
ada = true;
break;
}
}
if (!ada) {
// print("TAMBAH");
ou++;
} else {
Collections.sort(temp);
}
//print("MENJADI");
// print(temp);
// print("--------------");
}
print(ou);
}
} | JAVA |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> x;
int ans = 0;
for (int i = 0; i < n; i++) {
int t;
cin >> t;
x.push_back(t);
}
sort(x.begin(), x.end());
while (!x.empty()) {
for (int i = 0; i <= n; i++) {
if (lower_bound(x.begin(), x.end(), i) != x.end()) {
x.erase(lower_bound(x.begin(), x.end(), i));
} else {
ans++;
break;
}
}
}
cout << ans << endl;
return 0;
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 |
import java.util.*;
public class BruteForce{
public static Scanner in=new Scanner(System.in);
public static void main(String[]args){
int n=in.nextInt();
int[]z=new int[n];
for(int i=0;i<n;i++)
z[i]=in.nextInt();
Arrays.sort(z);
int count=0;
int given=0;
for(int i=0;i<n;i++){
if(given==n)
break;
else{
int cur=0;
int dist=0;
for(int j=i;j<n;j++){
if(z[j]!=-1&&cur<=z[j]){
cur++;
z[j]=-1;
dist++;
}
}
given+=cur;
if(dist>0)
count++;
}
}
System.out.println(count);
}
} | JAVA |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | 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)) | PYTHON3 |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | from sys import maxint
raw_input()
box_caps = map(int, raw_input().split(' '))
box_caps.sort(key=lambda x: -x)
stacks = []
while len(box_caps) != 0:
current_cap = box_caps.pop()
# Select for the current element a stack that it can hold with the lowest surplus capacity
selected_stack = None
min_surplus = maxint
for stack in stacks:
current_surplus = current_cap - len(stack)
if current_surplus >= 0 and current_surplus < min_surplus:
min_surplus = current_surplus
selected_stack = stack
if selected_stack is not None:
selected_stack.append(current_cap)
else:
# If no stack found that the current element can hold, create a new stack with it at the top
stacks.append([current_cap])
print len(stacks)
| PYTHON |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | /***** BY MURAD ******/
/*Everyone has a different way of thinking, so God Created us*/
/*Hope You Respect My Way..,Thank You*/
import java.io.*;
import java.math.BigInteger;
import java.util.*;
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
int n=in.nextInt();
int a[]=new int[n];
boolean vis[]=new boolean[n];
for(int i=0;i<n;i++)
a[i]=in.nextInt();
Arrays.sort(a);
int ans=0;
for(int i=0;i<n;i++)
{
if(vis[i])continue;
vis[i]=true;
int above=1;
for(int j=i+1;j<n;j++)
{
if(!vis[j]&&a[j]>=above){
above++;
vis[j]=true;
}
}
ans++;
}
out.println(ans);
out.flush();
}
static class Pair<C, I extends Number> implements Comparable<Pair<C, Number>> {
long value;
long idx;
Pair(long v, long i)
{
value = v;
idx = i;
}
@Override
public int compareTo(Pair<C, Number> p) {
return (int)(value - p.value);
}
}
static class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream), 32768);
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public long[] readLongArray(int n) {
long[] x = new long[n];
for (int i = 0; i < n; i++) {
x[i] = nextLong();
}
return x;
}
public int[] readIntArray(int n) {
int[] x = new int[n];
for (int i = 0; i < n; i++) {
x[i] = nextInt();
}
return x;
}
}
static class NumberTheory{
public static long gcd(long a,long b){
long c;
while (a != 0) {
c = a;
a = b % a;
b = c;
}
return b;
}
}
//Relatively Prime :- if diffrence between two number is equal to 1
} | JAVA |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.StringTokenizer;
public class A {
static StringTokenizer st;
static BufferedReader br;
static PrintWriter pw;
public static void main(String[] args) throws IOException {
br = new BufferedReader(new InputStreamReader(System.in));
pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int n = nextInt();
int[]x = new int[n+1];
for (int i = 1; i <= n; i++) {
x[i] = nextInt();
}
Arrays.sort(x, 1, n+1);
for (int i = 1; i <= n; i++) {
boolean ok = true;
int r = 1, h = 1;
for (int j = 1; j <= n; j++) {
if (x[j] < h-1) {
ok = false;
break;
}
r++;
if (r==i+1) {
r = 1;
h++;
}
}
if (ok) {
System.out.println(i);
return;
}
}
pw.close();
}
private static int nextInt() throws IOException {
return Integer.parseInt(next());
}
private static long nextLong() throws IOException {
return Long.parseLong(next());
}
private static double nextDouble() throws IOException {
return Double.parseDouble(next());
}
private static String next() throws IOException {
while (st==null || !st.hasMoreTokens())
st = new StringTokenizer(br.readLine());
return st.nextToken();
}
}
| JAVA |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++) {
cin >> v[i];
}
sort(v.rbegin(), v.rend());
int ans = n;
for (int i = 1; i < n; i++) {
vector<vector<int> > piles(i);
for (int j = 0; j < n; j++) piles[j % i].push_back(v[j]);
bool valid = true;
for (int j = 0; j < i; j++) {
for (int k = 0; k < piles[j].size(); k++)
if (piles[j].size() - k - 1 > piles[j][k]) valid = false;
}
if (valid) {
ans = i;
break;
}
}
cout << ans << endl;
return 0;
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | import java.util.*;
import java.io.*;
//DONT FORGET TO CHANGE CLASS NAME!
public class FoxBox {
public static void main(String[] args) throws IOException {
Scanner sc = new Scanner(System.in);
StringTokenizer st=new StringTokenizer(sc.nextLine());
int numBoxes=Integer.parseInt(st.nextToken());
st=new StringTokenizer(sc.nextLine());
int[] boxes=new int[numBoxes];
for(int i=0;i<boxes.length;i++){
boxes[i]=Integer.parseInt(st.nextToken());
}
Arrays.sort(boxes);
LinkedList<Integer> stacks= new LinkedList<Integer>();
for(int i=0;i<boxes.length;i++){
boolean set=false;
int boxStrength=boxes[i];
for(int k=0;k<stacks.size();k++){
int tmp=stacks.get(k);
if(tmp<=boxStrength){stacks.set(k,tmp+1);set=true;break;}
}
if(!set){stacks.add(1);}
}
System.out.println(stacks.size());
}
static class Coordinate {
int x, y;
public Coordinate(int x_, int y_) {
x = x_;
y = y_;
}
@Override
public String toString() {
return "(" + x + "," + y + ")";
}
}
}//Class Close Bracket
| JAVA |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int n;
int x[107];
bool cmpr(int a, int b) { return a > b; }
int main() {
cin >> n;
for (int i = 0; i < n; ++i) cin >> x[i];
sort(x, x + n, cmpr);
for (int ans = 1; ans <= n; ++ans) {
bool ok = true;
for (int i = 0; i < ans && ok; ++i) {
for (int j = i; j < n && ok; j += ans) {
if ((n - j - 1) / ans > x[j]) ok = false;
}
}
if (ok) {
cout << ans << endl;
return 0;
}
}
cout << n << endl;
return 0;
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | import java.io.*;
import java.util.*;
public class cf {
static class FastScanner {
BufferedReader br;
StringTokenizer st;
public FastScanner(Reader in) {
br = new BufferedReader(in);
}
public FastScanner() {
this(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String nextLine() {
String str = "";
try {
str = br.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return str;
}
int[] nextIntArray(int n) {
int[] a = new int[n];
for (int idx = 0; idx < n; idx++) {
a[idx] = nextInt();
}
return a;
}
}
static int mod = 1000000007;
public static void main(String[] args) {
FastScanner sc = new FastScanner();
PrintWriter pw = new PrintWriter(System.out);
int n = sc.nextInt();
int[] a = new int[n];
for(int i=0;i<n;i++)
a[i] = sc.nextInt();
Arrays.parallelSort(a);
int cnt = 0;
boolean[] vis = new boolean[n];
for(int i=0;i<n;i++) {
if(!vis[i]) {
cnt++;
int need = 1;
vis[i] = true;
for(int j=i+1;j<n;j++) {
if(!vis[j] && a[j] >= need) {
vis[j] = true;
need++;
}
}
}
}
pw.println(cnt);
pw.close();
}
}
| JAVA |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
long long n;
cin >> n;
vector<long long> vec(n);
for (int i = 0; i < n; i++) cin >> vec[i];
sort(vec.begin(), vec.end());
vector<long long> vis(n, 0);
long long tot = 0, ans = 0;
while (tot < n) {
long long cnt = 0;
ans++;
for (int i = 0; i < n; i++) {
if (!vis[i] && vec[i] >= cnt) {
cnt++;
vis[i] = 1;
tot++;
}
}
}
cout << ans << endl;
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | def solve(a):
a.sort()
res = 0
n = len(a)
while n > 0:
r = []
for i, x in enumerate(a):
if x == -1: continue
if x >= len(r):
r.append(x)
n -= 1
a[i] = -1
res += 1
return res
n = int(raw_input())
x = map(int, raw_input().split())
print solve(x)
| PYTHON |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int i, j, k, x, y, z, m, n, ans, p, q, r;
int ara[400];
int main() {
cin >> n;
for (i = 0; i < n; i++) cin >> ara[i];
sort(ara, ara + n);
ans = 0;
for (i = 0; i < n; i++) {
if (ara[i] == -1) continue;
x = ara[i];
ara[i] = -1;
for (j = i + 1, x = 1; j < n; j++) {
if (ara[j] >= x) {
ara[j] = -1;
x++;
}
}
ans++;
}
cout << ans;
return 0;
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 1e2 + 10;
int dp[maxn];
int n;
int a[maxn];
int mp[maxn];
int mo[maxn];
int v(int u) {
int res = 0;
for (int i = u; i < maxn; i++) {
res += mo[i];
}
return res;
}
void of(int k, int f) {
for (int i = k; i < maxn && f > 0; i++) {
if (mo[i] > 0) {
if (mo[i] < f) {
f -= mo[i];
mo[i] = 0;
} else {
mo[i] -= f;
f = 0;
}
}
}
return;
}
bool ok(int h) {
int o = n / h;
fill(mo, mo + maxn, 0);
if (n % h != 0) {
o++;
}
for (int i = 0; i < maxn; i++) {
mo[i] = mp[i];
}
for (int i = 0; i < o; i++) {
if (i != o - 1) {
if (v(i) < h) {
return 0;
}
of(i, h);
} else {
if (n % h == 0) {
if (v(i) < h) {
return 0;
}
of(i, h);
} else {
if (v(i) < (int)n % h) {
return 0;
}
of(i, h);
}
}
}
return 1;
}
int main() {
ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
mp[a[i]]++;
}
for (int i = 1; i <= n; i++) {
if (ok(i)) {
cout << i;
return 0;
}
}
return 0;
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | import java.io.*;
import java.util.*;
import static java.lang.Math.*;
public class Main {
public static void main(String args[]) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int[] data = new int[n];
StringTokenizer st = new StringTokenizer(br.readLine());
for (int i = 0; i < n; i++) {
data[i] = Integer.parseInt(st.nextToken());
}
Arrays.sort(data);
int piles = 0;
int start = 0;
while ((start = getStart(data)) != -1) {
int weight = 1;
data[start] = -1;
for (int i = start + 1; i < data.length; i++) {
if (data[i] == -1 || data[i] < weight) {
continue;
}
data[i] = -1;
weight++;
}
piles++;
}
System.out.println(piles);
}
public static int getStart(int[] data) {
for (int i = 0; i < data.length; i++) {
if (data[i] != -1) {
return i;
}
}
return -1;
}
} | JAVA |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
void solve() {
long long n;
cin >> n;
long long a[n];
for (long long int i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
vector<long long int> v;
v.push_back(0);
for (long long int i = 0; i < n; i++) {
long long j = 0;
while (1) {
if (j == (long long)v.size()) {
v.push_back(1);
break;
}
if (v[j] <= a[i]) {
v[j]++;
break;
}
j++;
}
}
cout << (long long)v.size();
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
long long TESTS = 1;
while (TESTS--) {
solve();
}
return 0;
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5, mod = 1e9 + 7;
multiset<int> q, v;
int n, a[maxn], cnt, ans;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
}
sort(a + 1, a + n + 1);
int cur = 1;
while (cur <= n) {
ans++;
int h = 0;
for (int i = 1; i <= n; i++)
if (a[i] >= h) {
h++;
a[i] = -11;
cur++;
}
}
cout << ans;
return 0;
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | # coding: utf-8
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)
| PYTHON3 |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int a[101];
bool b[101];
int main() {
int n, i, j, nrb, rasp = 0;
cin >> n;
for (i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + n + 1);
for (i = 1; i <= n; i++)
if (b[i] == 0) {
nrb = 1;
b[i] = 1;
j = i + 1;
while (j <= n) {
for (; j <= n; j++)
if (b[j] == 0 && a[j] >= nrb) break;
if (j <= n) {
nrb++;
b[j] = 1;
}
}
rasp++;
}
cout << rasp;
return 0;
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | import java.util.Scanner;
public class C {
public static void main(String args[]){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int a[] = new int[500];
for(int i=0;i<n;i++){
int b = in.nextInt();
a[b]++;
}
int temp = 0 , cavap = 0;
for(int i=0;i<500;i++){
temp+=a[i];
cavap=Math.max(cavap , (temp+i)/(i+1));
}
System.out.println(cavap);
}
}
| JAVA |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
const int maxn = 111;
int a[maxn];
int b[maxn];
int main() {
int n;
while (~scanf("%d", &n)) {
memset(b, 0, sizeof(b));
for (int i = 0; i < n; i++) {
scanf("%d", &a[i]);
b[a[i]]++;
}
sort(a, a + n);
int x = a[n - 1];
int t = n;
int sum = 0;
int tem = 0;
while (t) {
tem = 0;
for (int i = 0; i <= x; i++) {
while (b[i] && i >= tem) {
tem++;
b[i]--;
t--;
}
}
sum++;
}
printf("%d\n", sum);
}
return 0;
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | n=input()
a=map(int,raw_input().split())
a.sort()
p=[0]*n
c=0
for i in a:
for j in range(n):
if p[j]<=i:
p[j]+=1
c=max(c,j)
break
print c+1 | PYTHON |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
int a[101];
int used[101];
int p = 0;
int main() {
int n;
scanf("%d", &n);
int i, j;
for (i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
sort(a + 1, a + 1 + n);
for (i = 1; i <= n; i++) {
if (used[i] == 0) {
int t = 1;
p++;
used[i] = 1;
for (j = i + 1; j <= n; j++) {
if (a[j] >= t && used[j] == 0) {
used[j] = 1;
t++;
}
}
}
}
cout << p << endl;
return 0;
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | //package codeforces;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
public class FoxandBoxAccumulation {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
PrintWriter out = new PrintWriter(System.out);
int N = in.nextInt();
int[] x = new int[N];
boolean[] used = new boolean[N];
for (int i = 0; i < N; i++) {
x[i] = in.nextInt();
}
Arrays.sort(x);
int nUsed = 0;
int nPiles = 0;
while(nUsed < N) {
nUsed += createPile(N, x, used);
nPiles++;
}
out.println(nPiles);
out.flush();
}
private static int createPile(int N, int[] x, boolean[] used) {
int nBoxes = 0;
for (int i = 0; i < N; i++)
if (!used[i] && x[i] >= nBoxes) {
used[i] = true;
nBoxes++;
}
return nBoxes;
}
}
| JAVA |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
long long n, m, a[2000], s, k, l, i, j, b[2000], p;
int main() {
cin >> n;
for (i = 1; i <= n; i++) cin >> a[i];
sort(a + 1, a + 1 + n);
while (p == 0) {
p = 1;
l = 0;
for (i = 1; i <= n; i++)
if (l <= a[i] && b[i] == 0) {
l++;
b[i] = 1;
}
if (l != 0) {
k++;
p = 0;
}
}
cout << k;
return 0;
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
inline int init() {
int now = 0, ju = 1;
char c;
bool flag = false;
while (1) {
c = getchar();
if (c == '-')
ju = -1;
else if (c >= '0' && c <= '9') {
now = now * 10 + c - '0';
flag = true;
} else if (flag)
return now * ju;
}
}
inline long long llinit() {
long long now = 0, ju = 1;
char c;
bool flag = false;
while (1) {
c = getchar();
if (c == '-')
ju = -1;
else if (c >= '0' && c <= '9') {
now = now * 10 + c - '0';
flag = true;
} else if (flag)
return now * ju;
}
}
int gcd(int a, int b) {
if (b == 0)
return a;
else
return gcd(b, a % b);
}
int now[105];
int a[105];
int main() {
int n;
n = init();
for (int i = 1; i <= n; i++) {
a[i] = init();
}
int cnt = 0;
bool flag = false;
sort(a + 1, a + 1 + n);
for (int i = 1; i <= n; i++) {
flag = false;
for (int j = 1; j <= cnt; j++) {
if (a[i] >= now[j]) {
now[j]++;
flag = true;
break;
}
}
if (!flag) {
++cnt;
now[cnt] = 1;
}
}
printf("%d\n", cnt);
return 0;
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | #include <bits/stdc++.h>
using namespace std;
void solve();
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int test = 1;
while (test--) {
solve();
}
return 0;
}
void solve() {
int n;
cin >> n;
multiset<int> st;
for (int i = 0; i < n; i++) {
int x;
cin >> x;
st.insert(x);
}
int pile = 0;
while (st.size()) {
int x = 0;
while (1) {
auto it = st.lower_bound(x);
if (it == st.end()) break;
x++;
st.erase(it);
}
pile++;
}
cout << pile;
return;
}
| CPP |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | 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))
# 1536683664960
| PYTHON3 |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | 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):
# a must be sorted in decresing order
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:
# print(l, 0)
return 0
l[ind] += [i]
allowed[ind] = min(i, allowed[ind] - 1)
# print(l, 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))
| PYTHON3 |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | input()
X=sorted(map(int,raw_input().split()))
r=0
while X:
r+=1;X=X[1:];t=0
while 1:
l=[i for i in X if i>t]
if[]==l:break
X.remove(l[0]);t+=1
print r
| PYTHON |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | import java.io.*;
import java.util.*;
public class FoxAndBoxAccumulation {
public static void main(String[] args){
int n = ni();
int[] a = na(n);
Arrays.sort(a);
int i, group = 0, count;
for(i=0; i<n; i++){
if(a[i]!=-1){
group++;
count = 1;
for(int j=i+1; j<n; j++){
if(a[j]!=-1){
if(a[j] >= count){
count++;
a[j] = -1;
}
}
}
}
}
out.println(group);
out.flush();
}
static InputStream is = System.in;
static PrintWriter out = new PrintWriter(System.out);
static BufferedReader bf = new BufferedReader(new InputStreamReader(is));
static String INPUT = "";
private static byte[] inbuf = new byte[1024];
private static int lenbuf = 0;
private static int ptrbuf = 0;
private static int readByte()
{
if(lenbuf == -1)throw new InputMismatchException();
if(ptrbuf >= lenbuf){
ptrbuf = 0;
try { lenbuf = is.read(inbuf); } catch (IOException e) { throw new InputMismatchException(); }
if(lenbuf <= 0)return -1;
}
return inbuf[ptrbuf++];
}
private static boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); }
private static int skip() { int b; while((b = readByte()) != -1 && isSpaceChar(b)); return b; }
private static double nd() { return Double.parseDouble(ns()); }
private static char nc() { return (char)skip(); }
private static String ns()
{
int b = skip();
StringBuilder sb = new StringBuilder();
while(!(isSpaceChar(b))){ // when nextLine, (isSpaceChar(b) && b != ' ')
sb.appendCodePoint(b);
b = readByte();
}
return sb.toString();
}
private static String rl()
{
try {
return bf.readLine();
} catch (IOException e) {
e.printStackTrace();
}
return null;
}
private static char[] ns(int n)
{
char[] buf = new char[n];
int b = skip(), p = 0;
while(p < n && !(isSpaceChar(b))){
buf[p++] = (char)b;
b = readByte();
}
return n == p ? buf : Arrays.copyOf(buf, p);
}
private static char[][] nm(int n, int m)
{
char[][] map = new char[n][];
for(int i = 0;i < n;i++)map[i] = ns(m);
return map;
}
private static int[] na(int n)
{
int[] a = new int[n];
for(int i = 0;i < n;i++)a[i] = ni();
return a;
}
private static int ni()
{
int num = 0, b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
private static long nl()
{
long num = 0;
int b;
boolean minus = false;
while((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-'));
if(b == '-'){
minus = true;
b = readByte();
}
while(true){
if(b >= '0' && b <= '9'){
num = num * 10 + (b - '0');
}else{
return minus ? -num : num;
}
b = readByte();
}
}
} | JAVA |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | import java.io.*;
import java.util.*;
public class problem389C {
public static void main (String[]args)throws IOException{
BufferedReader x = new BufferedReader(new InputStreamReader(System.in));
int n=Integer.parseInt(x.readLine());
StringTokenizer st=new StringTokenizer(x.readLine());
int[]values=new int[n];
for (int i=0; i<n; i++){
values[i]=Integer.parseInt(st.nextToken());
}
Arrays.sort(values);
boolean[]used=new boolean[n];
int counter=0;
int dp=0;
int numstacks=0;
while (counter<n){
dp=0;
for (int i=0; i<n; i++){
if (!used[i]){
if (dp<=values[i]){
dp++;
counter++;
used[i]=true;
}
}
}
numstacks++;
}
System.out.println(numstacks);
System.exit(0);
}
} | JAVA |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | import java.io.*;
import java.util.*;
public class FoxAndBoxAccumulation
{
public static void main(String[] args) throws IOException
{
Scanner in = new Scanner(System.in);
StringBuilder out = new StringBuilder();
int n, ind, t;
int[] boxes;
ArrayList<LinkedList<Integer>> piles = new ArrayList<LinkedList<Integer>>();
for (int i = 0; i < 1; i++)
{
n = in.nextInt();
piles.clear();
boxes = new int[n];
for ( t = 0; t < n; t++)
boxes[t]=in.nextInt();
Arrays.sort(boxes);
for ( t = 0; t < 100; t++)
piles.add(new LinkedList<Integer>());
ind = 0;
for (int j = 0; j < n; j++) {
if(piles.get(ind).size()==0 )
piles.get(ind).add(boxes[j]);
else if(boxes[j] >= piles.get(ind).size())
piles.get(ind).add(boxes[j]);
else{
for ( t = ind+1; ; t = (t+1)%piles.size()) {
if(piles.get(t).size()==0 || boxes[j] >= piles.get(t).size())
{
piles.get(t).add(boxes[j]);
break;
}
}
}
}
for (t = 0; t < piles.size(); t++)
if(piles.get(t).size() == 0)
break;
//System.out.println(piles);
System.out.println(t);
}
}
} | JAVA |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | import sys
import collections
case = int(sys.stdin.readline());
test = sys.stdin.readline().split(" ");
num = [int(x) for x in test]
stats = collections.defaultdict(int);
for i in num:
stats[i]+=1;
key = sorted(stats)
total = 0;
while sum(stats.values())>0:
stack = [];
for i in key:
if(stats[i]>0):
while(len(stack)<=i and stats[i]>0):
stack.append(i);
stats[i]-=1;
total+=1
print(total)
| PYTHON3 |
389_C. Fox and Box Accumulation | 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> | 2 | 9 | import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskC solver = new TaskC();
solver.solve(1, in, out);
out.close();
}
}
class TaskC {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt();
int []a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = in.nextInt();
}
Arrays.sort(a);
int []piles = new int[n];
for(int x:a)
for (int i = 0; i < n; i++) {
if (piles[i] <= x){
piles[i]++;
break;
}
}
int res = 0;
for(int x:piles)if (x > 0)res++;
out.print(res);
}
}
class InputReader {
public BufferedReader reader;
public StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
try {
tokenizer = new StringTokenizer(reader.readLine());
} catch (IOException e) {
throw new RuntimeException(e);
}
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
}
| JAVA |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.