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 | import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;
import static java.lang.Math.*;
/* spar5h */
public class cf1 implements Runnable{
public void run() {
InputReader s = new InputReader(System.in);
PrintWriter w = new PrintWriter(System.out);
int n = s.nextInt();
int[] f = new int[100 + 1];
for(int i = 0; i < n; i++)
f[s.nextInt()]++;
int res = 0;
for(int i = 1; i <= n + 1; i++) {
int bottom = -1;
for(int j = 100; j >= 0; j--) {
if(f[j] > 0) {
bottom = j; break;
}
}
for(int j = bottom; j >= 0; j--) {
if(f[j] == 0) {
for(int k = j + 1; k <= 100; k++) {
if(f[k] > 0) {
f[k]--; break;
}
}
}
else
f[j]--;
}
if(bottom == -1) {
res = i - 1; break;
}
}
w.println(res);
w.close();
}
static class InputReader {
private InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public InputReader(InputStream stream) {
this.stream = stream;
}
public int read() {
if (numChars==-1)
throw new InputMismatchException();
if (curChar >= numChars) {
curChar = 0;
try {
numChars = stream.read(buf);
}
catch (IOException e) {
throw new InputMismatchException();
}
if(numChars <= 0)
return -1;
}
return buf[curChar++];
}
public String nextLine() {
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str = "";
try {
str = br.readLine();
}
catch (IOException e) {
e.printStackTrace();
}
return str;
}
public int nextInt() {
int c = read();
while(isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
int res = 0;
do {
if(c<'0'||c>'9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public long nextLong() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
long res = 0;
do {
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
while (!isSpaceChar(c));
return res * sgn;
}
public double nextDouble() {
int c = read();
while (isSpaceChar(c))
c = read();
int sgn = 1;
if (c == '-') {
sgn = -1;
c = read();
}
double res = 0;
while (!isSpaceChar(c) && c != '.') {
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
res *= 10;
res += c - '0';
c = read();
}
if (c == '.') {
c = read();
double m = 1;
while (!isSpaceChar(c))
{
if (c == 'e' || c == 'E')
return res * Math.pow(10, nextInt());
if (c < '0' || c > '9')
throw new InputMismatchException();
m /= 10;
res += (c - '0') * m;
c = read();
}
}
return res * sgn;
}
public String readString() {
int c = read();
while (isSpaceChar(c))
c = read();
StringBuilder res = new StringBuilder();
do {
res.appendCodePoint(c);
c = read();
}
while (!isSpaceChar(c));
return res.toString();
}
public boolean isSpaceChar(int c) {
if (filter != null)
return filter.isSpaceChar(c);
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public String next() {
return readString();
}
public interface SpaceCharFilter {
public boolean isSpaceChar(int ch);
}
}
public static void main(String args[]) throws Exception {
new Thread(null, new cf1(),"cf1",1<<26).start();
}
} | 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 BoxAccumulation {
public static void main(String[]args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int [] arr = new int[n];
StringTokenizer st = new StringTokenizer(br.readLine());
boolean [] used = new boolean[n];
for (int i = 0; i < n; i++) {
arr[i] = Integer.parseInt(st.nextToken());
}
Arrays.sort(arr);
int res = 0;
int count = 0;
int top = 0;
while (count < n) {
for (int i = 0; i < n; i++) {
if (!used[i] && arr[i] >= top) {
used[i] = true;
top++;
count++;
}
}
top = 0;
res++;
}
System.out.println(res);
}
}
| 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 static java.lang.Math.*;
import static java.util.Arrays.*;
public class A {
private final static boolean autoflush = false;
public A () {
int N = sc.nextInt();
Integer [] A = sc.nextInts();
int [] K = new int [101];
for (int i : A)
++K[i];
int p = 0, q = N, m;
while (q - p > 1)
if (eval(m = (p+q)/2, copyOf(K, 101)))
q = m;
else
p = m;
exit(q);
}
boolean eval(int M, int [] K) {
int [] T = new int [M]; fill(T, INF);
int z = 100;
for(;;) {
boolean bad = true;
for (int i : rep(M)) {
while (z >= 0 && K[z] == 0)
--z;
if (z == -1)
return true;
if (T[i] > 0) {
T[i] = min(T[i] - 1, z);
--K[z];
bad = false;
}
}
if (bad)
return false;
}
}
///////////////////////////////////////////////////////////////////////////
private static final int INF = (int) 1e9;
///////////////////////////////////////////////////////////////////////////
private static int [] rep(int N) { return rep(0, N); }
private static int [] rep(int S, int T) { if (T <= S) return new int [0]; int [] res = new int [T-S]; for (int i = S; i < T; ++i) res[i-S] = i; return res; }
////////////////////////////////////////////////////////////////////////////////////
private final static MyScanner sc = new MyScanner();
private static class MyScanner {
public String next() { newLine(); return line[index++]; }
public int nextInt() { return Integer.parseInt(next()); }
public String nextLine() { line = null; return readLine(); }
public String [] nextStrings() { return nextLine().split(" "); }
public Integer [] nextInts() {
String [] L = nextStrings();
Integer [] res = new Integer [L.length];
for (int i = 0; i < L.length; ++i)
res[i] = Integer.parseInt(L[i]);
return res;
}
//////////////////////////////////////////////
private boolean eol() { return index == line.length; }
private String readLine() {
try {
return r.readLine();
} catch (Exception e) {
throw new Error (e);
}
}
private final java.io.BufferedReader r;
private MyScanner () { this(new java.io.BufferedReader(new java.io.InputStreamReader(System.in))); }
private MyScanner (java.io.BufferedReader r) {
try {
this.r = r;
while (!r.ready())
Thread.sleep(1);
start();
} catch (Exception e) {
throw new Error(e);
}
}
private String [] line;
private int index;
private void newLine() {
if (line == null || eol()) {
line = readLine().split(" ");
index = 0;
}
}
}
private static void print (Object o, Object... a) { printDelim(" ", o, a); }
private static void printDelim (String delim, Object o, Object... a) { pw.println(build(delim, o, a)); }
private static void exit (Object o, Object... a) { print(o, a); exit(); }
private static void exit() {
pw.close();
System.out.flush();
System.err.println("------------------");
System.err.println("Time: " + ((millis() - t) / 1000.0));
System.exit(0);
}
////////////////////////////////////////////////////////////////////////////////////
private static String build (String delim, Object o, Object... a) {
StringBuilder b = new StringBuilder();
append(b, o, delim);
for (Object p : a)
append(b, p, delim);
return b.substring(delim.length());
}
private static void append(StringBuilder b, Object o, String delim) {
if (o.getClass().isArray()) {
int L = java.lang.reflect.Array.getLength(o);
for (int i = 0; i < L; ++i)
append(b, java.lang.reflect.Array.get(o, i), delim);
} else if (o instanceof Iterable<?>)
for (Object p : (Iterable<?>)o)
append(b, p, delim);
else
b.append(delim).append(o);
}
////////////////////////////////////////////////////////////////////////////////////
private static void start() { t = millis(); }
private static java.io.PrintWriter pw = new java.io.PrintWriter(System.out, autoflush);
private static long t;
private static long millis() { return System.currentTimeMillis(); }
public static void main (String[] args) { new A(); exit(); }
}
| 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, x[105];
while (~scanf("%d", &n)) {
for (int i = 1; i <= n; i++) {
scanf("%d", &x[i]);
}
sort(x + 1, x + 1 + n);
int ans = 0, num, j;
for (int i = 1; i <= n; i++) {
if (x[i] != -1) {
ans++;
x[i] = -1;
num = 1;
j = i;
while (j <= n) {
j++;
if (x[j] >= num) {
x[j] = -1;
num++;
}
}
}
}
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 | input();print(1+max(x//-~f for x,f in enumerate(sorted(map(int,input().split()))))) | 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 | I=lambda:list(map(int,input().split()))
n,=I()
l=I()
l.sort()
ans=0
i=0
k=1
while i<n:
if l[i]<i//k:
k+=1
i+=1
print(k)
| 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 | def take_lightest_box(boxes):
for i in range(101):
if i in boxes:
boxes[i] -= 1
if boxes[i] == 0:
del boxes[i]
return i
piles = []
boxes = {}
input()
tmp = input()
x = [int(i) for i in tmp.split(" ")]
for item in x:
if item in boxes:
boxes[item] = boxes[item] + 1
else:
boxes[item] = 1
while len(boxes) > 0:
lightest = take_lightest_box(boxes)
for pile in piles:
if len(pile) <= lightest:
pile.append(lightest)
break
else:
piles.append([lightest])
print(len(piles))
| 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;
const int M = 1000000007;
const int N = 2e6;
void solve() {
int n;
cin >> n;
int arr[n];
for (int i = 0; i < n; i++) cin >> arr[i];
sort(arr, arr + n);
int cnt = 0;
long long ans = 0;
while (cnt < n) {
ans++;
int h = 0;
for (int i = 0; i < n; i++) {
if (arr[i] >= h) {
arr[i] = -1;
h++;
cnt++;
}
}
}
cout << ans << "\n";
}
int main() {
ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int PP = 1;
while (PP--) {
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 | import java.util.Scanner;
import java.io.OutputStream;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author rabeckiy
*/
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 {
public void solve(int testNumber, Scanner in, PrintWriter out) {
int n = in.nextInt();
int[] x = new int[101];
for(int i = 0; i<n; i++)
x[in.nextInt()]++;
int cb = 0, res = 0;
boolean was = false, end = false;
while(!end){
for(int i = cb; i<=100&&!was; i++){
if(x[i]>0){
if(x[i] > i + 1 - cb) {
x[i] -= i + 1 - cb;
cb += i + 1 - cb;
} else {
cb += x[i];
x[i] = 0;
}
was = true;
}
}
if(was)
was = false;
else if(cb==0)
end = true;
else {
cb = 0;
res++;
}
}
out.println(res);
}
}
| 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);
cin.tie(0);
cout.tie(0);
int n;
cin >> n;
vector<int> a(n);
for (int i = 0; i < n; ++i) cin >> a[i];
sort(a.begin(), a.end());
vector<int> v;
for (int i = 0; i < n; ++i) {
int val = a[i], idx = -1;
for (int j = 0; j < (int)v.size(); ++j) {
if (val >= v[j]) {
idx = j;
v[j]++;
break;
}
}
if (idx == -1) v.push_back(1);
}
cout << v.size() << "\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 INF = INT_MAX;
const long long INFL = LLONG_MAX;
const long double pi = acos(-1);
int dx[] = {1, -1, 0, 0};
int dy[] = {0, 0, 1, -1};
int main() {
ios_base::sync_with_stdio(0);
cout.precision(15);
cout << fixed;
cout.tie(0);
cin.tie(0);
int n;
cin >> n;
map<int, int> m;
for (int(i) = 0; (i) < (n); (i)++) {
int x;
cin >> x;
m[x]++;
}
long long ans = 0;
while (1) {
int ct = 0;
for (int(i) = 0; (i) < (101); (i)++) {
ct += m[i] == 0;
}
if (ct == 101) break;
int up = 0;
for (int(i) = 0; (i) < (101); (i)++) {
while (up <= i && m[i]) up++, m[i]--;
}
ans++;
}
cout << ans << '\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 | 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;
FastScanner in = new FastScanner(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA solver = new TaskA();
solver.solve(1, in, out);
out.close();
}
}
class TaskA {
public void solve(int testNumber, FastScanner in, PrintWriter out) {
int n = in.nextInt();
int[] a = ArrayUtils.readIntArray(in, n);
Arrays.sort(a);
int k = 1;
while (!can(a, k))
k++;
out.print(k);
}
boolean can(int[] a, int k) {
for (int i = 0; i < a.length; i++)
if (a[i] < i / k)
return false;
return true;
}
}
class FastScanner {
BufferedReader reader;
StringTokenizer tokenizer;
public FastScanner(InputStream inputStream) {
reader = new BufferedReader(new InputStreamReader(inputStream));
}
public String nextToken() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
String line;
try {
line = reader.readLine();
} catch (IOException e) {
return null;
}
tokenizer = new StringTokenizer(line);
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(nextToken());
}
}
class ArrayUtils {
public static int[] readIntArray(FastScanner in, int count) {
int[] array = new int[count];
for (int i = 0; i < count; i++)
array[i] = in.nextInt();
return array;
}
}
| 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.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.HashSet;
public class june {
static Reader r = new Reader();
static PrintWriter out = new PrintWriter(System.out);
private static void solve1() throws IOException {
int n = r.nextInt();
int arr[] = r.nextIntArray(n);
int i = 1;
while (i <= n) {
for (int j = 0; j < n; j++) {
if (arr[j] == i) {
out.print(j + 1 + " ");
}
}
i++;
}
// out.print(res);
out.close();
}
static class Point implements Comparable<Point> {
int x, y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
@Override
public int compareTo(Point o) {
if (x == o.x) {
return (y - o.y);
}
return (o.x - x);
}
}
private static void solve2() throws IOException {
int n = r.nextInt();
int k = r.nextInt();
Point arr[] = new Point[n];
for (int i = 0; i < n; i++) {
arr[i] = new Point(r.nextInt(), r.nextInt());
}
Arrays.sort(arr);
int ans = 0;
int prob = arr[k - 1].x, pen = arr[k - 1].y;
for (int i = 0; i < n; i++) {
if (arr[i].x == prob && arr[i].y == pen) {
ans++;
}
}
out.print(ans);
out.close();
}
private static void solve3() throws IOException {
int n = r.nextInt();
int arr[] = r.nextIntArray(n);
Arrays.sort(arr);
HashSet<Integer> set = new HashSet<Integer>();
int ans = 0;
while (n > 0) {
int cnt = 0;
for (int i = 0; i < arr.length; i++) {
if (arr[i] >= cnt && !set.contains(i)) {
cnt++;
n--;
set.add(i);
}
}
ans++;
}
out.print(ans);
out.close();
}
private static void solve4() throws IOException {
int t = r.nextInt();
StringBuilder res = new StringBuilder();
while (t-- > 0) {
int n = r.nextInt();
res.append(false).append("\n");
}
out.print(res);
out.close();
}
private static void solve5() throws IOException {
int t = r.nextInt();
StringBuilder res = new StringBuilder();
while (t-- > 0) {
int n = r.nextInt();
res.append(false).append("\n");
}
out.print(res);
out.close();
}
private static void solve6() throws IOException {
int t = r.nextInt();
StringBuilder res = new StringBuilder();
while (t-- > 0) {
int n = r.nextInt();
res.append(false).append("\n");
}
out.print(res);
out.close();
}
public static void main(String[] args) throws IOException {
// solve1();
// solve2();
solve3();
// solve4();
// solve5();
// solve6();
}
static class Reader {
final private int BUFFER_SIZE = 1 << 12;
boolean consume = false;
private byte[] buffer;
private int bufferPointer, bytesRead;
private boolean reachedEnd = false;
public Reader() {
buffer = new byte[BUFFER_SIZE];
bufferPointer = 0;
bytesRead = 0;
}
public boolean hasNext() {
return !reachedEnd;
}
private void fillBuffer() throws IOException {
bytesRead = System.in.read(buffer, bufferPointer = 0, BUFFER_SIZE);
if (bytesRead == -1) {
buffer[0] = -1;
reachedEnd = true;
}
}
private void consumeSpaces() throws IOException {
while (read() <= ' ' && reachedEnd == false)
;
bufferPointer--;
}
private byte read() throws IOException {
if (bufferPointer == bytesRead) {
fillBuffer();
}
return buffer[bufferPointer++];
}
public String next() throws IOException {
StringBuilder sb = new StringBuilder();
consumeSpaces();
byte c = read();
do {
sb.append((char) c);
} while ((c = read()) > ' ');
if (consume) {
consumeSpaces();
}
;
if (sb.length() == 0) {
return null;
}
return sb.toString();
}
public String nextLine() throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String str = br.readLine();
return str;
}
public int nextInt() throws IOException {
consumeSpaces();
int ret = 0;
byte c = read();
boolean neg = (c == '-');
if (neg) {
c = read();
}
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (consume) {
consumeSpaces();
}
if (neg) {
return -ret;
}
return ret;
}
public long nextLong() throws IOException {
consumeSpaces();
long ret = 0;
byte c = read();
boolean neg = (c == '-');
if (neg) {
c = read();
}
do {
ret = ret * 10L + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (consume) {
consumeSpaces();
}
if (neg) {
return -ret;
}
return ret;
}
public double nextDouble() throws IOException {
consumeSpaces();
double ret = 0;
double div = 1;
byte c = read();
boolean neg = (c == '-');
if (neg) {
c = read();
}
do {
ret = ret * 10 + c - '0';
} while ((c = read()) >= '0' && c <= '9');
if (c == '.') {
while ((c = read()) >= '0' && c <= '9') {
ret += (c - '0') / (div *= 10);
}
}
if (consume) {
consumeSpaces();
}
if (neg) {
return -ret;
}
return ret;
}
public int[] nextIntArray(int n) throws IOException {
int[] a = new int[n];
for (int i = 0; i < n; i++) {
a[i] = nextInt();
}
return a;
}
public long[] nextLongArray(int n) throws IOException {
long[] a = new long[n];
for (int i = 0; i < n; i++) {
a[i] = nextLong();
}
return a;
}
public int[][] nextIntMatrix(int n, int m) throws IOException {
int[][] grid = new int[n][m];
for (int i = 0; i < n; i++) {
grid[i] = nextIntArray(m);
}
return grid;
}
public char[][] nextCharacterMatrix(int n) throws IOException {
char[][] a = new char[n][];
for (int i = 0; i < n; i++) {
a[i] = next().toCharArray();
}
return a;
}
public void close() throws IOException {
if (System.in == null) {
return;
} else {
System.in.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 inf = 0x3f3f3f3f;
int a[102];
int n;
int cnt = 0;
int cou[101];
int main() {
scanf("%d", &n);
int x;
memset(a, inf, sizeof(a));
for (int i = 1; i <= n; i++) {
scanf("%d", &a[i]);
}
sort(a + 1, a + 1 + n);
for (int i = 1; i <= n; i++) {
int bl = 0;
for (int j = 1; j <= cnt; j++) {
if (a[i] >= cou[j]) {
cou[j]++;
bl = 1;
break;
}
}
if (bl == 0) {
cnt++;
cou[cnt]++;
}
}
printf("%d", 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 main() {
long long t;
cin >> t;
long long a[t];
for (int i = 0; i < t; i++) cin >> a[i];
sort(a, a + t);
long long c = 0, i;
for (i = 0; i < t; i++) {
if (c * (a[i] + 1) <= i) c++;
}
cout << c;
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 a[110];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
int ret;
cin >> ret;
a[ret]++;
}
int res = 0;
for (;;) {
int k = -1;
for (int i = 0; i <= 100; i++)
if (a[i]) {
k = i;
break;
}
if (k == -1) break;
res++;
for (int i = 0;; i++) {
while (k <= 100 && (a[k] == 0 || k < i)) k++;
if (k > 100) break;
a[k]--;
}
}
cout << res << 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 | def validate_stack(stack):
for i in range(len(stack)):
if stack[i] < len(stack)-i-1:
return False
return True
# print(validate_stack([4,4,4,4,4]))
if __name__ == '__main__':
n = int(input())
box_strength = [int(x) for x in input().split()]
box_strength = sorted(box_strength, reverse = True)
flag = True
ans = 100
for i in range(1,n+1):
matrix = [[] for x in range(i)]
flag = True
ans = i
# print(matrix)
for idx, j in enumerate(box_strength):
# print(idx%i,j)
matrix[idx%i].append(j)
# print(matrix)
for stack in matrix:
if not validate_stack(stack):
flag = False
break
if flag:
break
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.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Arrays;
import java.util.ArrayList;
import java.util.StringTokenizer;
public class FoxAndBoxAccumulation {
public static void main(String[] args) {
MyScanner sc = new MyScanner();
int N = sc.nextInt();
int[] arr = new int[N];
for (int i = 0; i < N; i++) {
arr[i] = sc.nextInt();
}
Arrays.sort(arr);
ArrayList<Integer> lst = new ArrayList<Integer>();
for (int x : arr) {
lst.add(x);
}
int cnt = 0;
while (!lst.isEmpty()) {
ArrayList<Integer> next = new ArrayList<Integer>();
int pileSize = 0;
for (Integer x : lst) {
if (x >= pileSize) {
pileSize++;
} else {
next.add(x);
}
}
lst = next;
cnt++;
}
System.out.println(cnt);
}
public static class MyScanner {
BufferedReader br;
StringTokenizer st;
public MyScanner() {
br = new BufferedReader(new InputStreamReader(System.in));
}
int nextInt() {
return Integer.parseInt(next());
}
long nextLong() {
return Long.parseLong(next());
}
double nextDouble() {
return Double.parseDouble(next());
}
String next() {
while (st == null || !st.hasMoreElements()) {
try {
st = new StringTokenizer(br.readLine());
} catch (IOException e) {
e.printStackTrace();
}
}
return st.nextToken();
}
String nextLine() {
String str = "";
try { str = br.readLine(); }
catch (IOException e) { e.printStackTrace(); }
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,p=int(input()),0
a=sorted(map(int,input().split()))
for i in range(n):
if p*(a[i]+1)<=i:p+=1
print(p) | 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.*;
import java.util.Scanner;
import java.io.*;
import javax.lang.model.util.ElementScanner6;
import static java.lang.System.out;
import java.util.Stack;
import java.util.Queue;
import java.util.LinkedList;
public class A388
{
public static void main(String args[])
{
FastReader in=new FastReader();
PrintWriter pr = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int tc=1;
//tc=in.nextInt();
while(tc-->0)
{
int n=in.nextInt();
int arr[]=new int[n];
for(int i=0;i<n;i++)
{
arr[i]=in.nextInt();
}
sort(arr);
int ans=1;
for(int i=1;i<n;i++)
{
int least=i/ans;
if(arr[i]<least)ans++;
}
pr.println(ans);
}
pr.flush();
}
static void sort(long[] a) {
ArrayList<Long> l = new ArrayList<>();
for (long i : a)
l.add(i);
Collections.sort(l);
for (int i = 0; i < a.length; i++)
a[i] = l.get(i);
}
static void sort(int[] a) {
ArrayList<Integer> l = new ArrayList<>();
for (int i : a)
l.add(i);
Collections.sort(l);
for (int i = 0; i < a.length; i++)
a[i] = l.get(i);
}
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(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());
}
int[] readIntArray(int n)
{
int a[]=new int[n];
for(int i=0;i<n;i++)a[i]=nextInt();
return a;
}
long[] readLongArray(int n)
{
long a[]=new long[n];
for(int i=0;i<n;i++)a[i]=nextLong();
return a;
}
String nextLine()
{
String str = "";
try
{
str = br.readLine();
}
catch (IOException e)
{
e.printStackTrace();
}
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=int(input())
l=list(map(int,input().split()))
l.sort()
ans=0
while len(l):
s=[]
b=0
for i in range(len(l)):
if b<=l[i]:
b=b+1
# print(l[i],end=" ")
else:
s.append(l[i])
ans=ans+bool(b)
l=s
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 n;
vector<int> v(100);
bool a[100] = {0};
int ans = 0;
int main() {
std::ios_base::sync_with_stdio(false);
cin >> n;
for (int i = 0; i < n; i++) cin >> v[i];
sort(v.begin(), v.begin() + n);
for (int i = 0; i < n; i++) {
if (a[i]) continue;
int mx = 1;
a[i] = 1;
ans++;
for (int j = i; j < n; j++) {
if (a[j]) continue;
if (v[j] >= mx) {
mx++;
a[j] = 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 | #!/usr/bin/env python
# -*- coding: UTF-8 -*-
import time
import sys, io
import re, math
#start = time.clock()
n=input()
l=[int(x) for x in raw_input().split()]
l.sort()
chk=l[:]
ans=[]
jk=0
while len(l):
l=chk[:]
ans.append([])
for i in range(len(l)):
if i==0:
ans[jk].append(l[i])
chk.remove(l[i])
elif l[i]>=len(ans[jk]):
ans[jk].append(l[i])
chk.remove(l[i])
jk+=1
#print ans
print len(ans)-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 | import sys
if __name__ == '__main__':
_ = sys.stdin.readline().split()
boxes = map(int, sys.stdin.readline().split())
boxes = sorted(boxes)
piles = []
for b in boxes:
put = False
for p in piles:
if len(p) <= b:
p.append(b)
put = True
break
if not put:
piles.append([b])
# print piles
print len(piles)
| 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 = 105;
int n;
int sz[N], len;
int cnt[N];
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) {
int x;
scanf("%d", &x);
++cnt[x];
}
len = cnt[0];
for (int i = 1; i <= len; ++i) sz[i] = 1;
for (int i = 1; i <= 100; ++i) {
for (int j = 1; j <= len; ++j) {
while (cnt[i] > 0 && sz[j] < i + 1) {
++sz[j];
--cnt[i];
}
}
while (cnt[i] > 0) {
sz[++len] = 1;
--cnt[i];
while (cnt[i] > 0 && sz[len] < i + 1) {
++sz[len];
--cnt[i];
}
}
}
printf("%d\n", len);
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 | def main():
n = int(input())
strength = list(map(int,input().split()))
strengths = {}
for i in strength:
if i not in strengths.keys():
strengths[i] = 1
else:
strengths[i] += 1
boxes = []
for i in strengths.keys():
boxes.append([i,strengths[i]])
boxes.sort()
piles = []
piles.append([boxes[0][0]])
boxes[0][1] -= 1
for i in range(len(boxes)):
curr = boxes[i][0]
count = boxes[i][1]
while count > 0:
found = False
for j in range(len(piles)):
if count > 0:
if len(piles[j]) <= curr:
piles[j].append(curr)
count -= 1
found = True
if not found:
break
if count > 0:
total = count//(curr+1)
#print(count,total)
for j in range(total):
pile = []
for k in range(curr+1):
pile.append(curr)
piles.append(pile)
if count%(curr+1) != 0:
pile = []
for j in range(count%(curr+1)):
pile.append(curr)
piles.append(pile)
#print(piles)
print(len(piles))
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 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, a[105], j, i, count = 0, res = 1, idx = 0;
cin >> n;
int b[105] = {0};
for (i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
for (i = 1; i < n; i++) {
if (i / res > a[i]) res++;
}
cout << res << 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())
listn=list(map(int, input().split()))
listn=sorted(listn)
i=0
res=0
vis=[]
while i<n:
res+=1
currPile=[]
k=0
while k<n:
if listn[k]>=len(currPile) and not k in vis:
i+=1; vis.append(k); currPile.append(1)
k+=1
print(res) | 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.*;
public class C {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] strength = new int[n];
boolean[] used = new boolean[n];
for(int i = 0; i < n; i++) {
strength[i] = in.nextInt();
}
Arrays.sort(strength);
int piles = 0;
for(int i = 0; i < n; i++) {
int boxesOnTop = 0;
// int currentBest = Integer.MAX_VALUE;
boolean pileMade = false;
for(int k = 0; k < n; k++) {
if(!used[k] && strength[k] >= boxesOnTop ) {
//currentBest = strength[k];
//System.out.println("ile made");
boxesOnTop++;
used[k] = true;
pileMade = true;
}
}
if(pileMade) {
piles+=1;
}
}
System.out.println(piles);
}
} | 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;
public class C {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] A = new int[101];
for (int i = 0; i < n; i++)
A[in.nextInt()]++;
int last = A[0];
int size = A[0];
for (int i = 1; i < 101; i++) {
if (A[i] <= last) {
last += size - A[i];
last = Math.min(last, 1000);
} else {
A[i] -= last;
int add = (int) Math.ceil(A[i] * 1.0 / (i + 1));
size += add;
last = size + (i + 1 - A[i] % (i + 1)) % (i + 1);
}
}
System.out.println(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 a[101];
int main() {
int n, i, j;
cin >> n;
for (i = 0; i < n; i++) {
cin >> j;
a[j]++;
}
int numbox = 0, piles = 0, flag;
while (1) {
numbox = 0;
flag = 0;
for (i = 0; i <= 100; i++) {
if (a[i] > 0 && numbox <= i) {
flag = 1;
a[i]--;
numbox++;
i--;
}
}
if (flag == 1)
piles++;
else
break;
}
cout << piles;
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() {
int n, j, k, m, l, f, y;
char ch;
vector<vector<int>> v;
vector<int> p;
cin >> n;
vector<int> q(n + 2, 0);
for (int i = 0; i < n; i++) {
v.push_back(q);
}
for (int i = 0; i < n; i++) {
cin >> k;
p.push_back(k);
}
sort(p.begin(), p.end());
m = 0;
for (int i = 0; i < n; i++) {
f = 1;
while (f) {
l = 0;
for (int s = 0; s < n; s++) {
if (v[l][0] > p[i]) {
l++;
} else {
y = v[l][0] + 1;
v[l][y] = p[i];
v[l][0]++;
s = n;
f = 0;
}
}
}
}
f = 1;
l = 0;
for (int i = 0; i < n; i++) {
if (v[i][0] != 0) m = i;
}
m++;
cout << m;
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()
no=map(int,raw_input().split())
no.sort()
ans=[[no[0]]]
for i in xrange(1,n):
f=0
for j in xrange(len(ans)):
if len(ans[j])<=no[i]:
ans[j].append(no[i])
f=1
break
if f==0:
ans.append([no[i]])
print len(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 | """
// Author : snape_here - Susanta Mukherjee
"""
from __future__ import division, print_function
import os,sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
from __builtin__ import xrange as range
from future_builtins import ascii, filter, hex, map, oct, zip
def ii(): return int(input())
def fi(): return float(input())
def si(): return input()
def msi(): return map(str,input().split())
def mi(): return map(int,input().split())
def li(): return list(mi())
def read():
sys.stdin = open('input.txt', 'r')
sys.stdout = open('output.txt', 'w')
def gcd(x, y):
while y:
x, y = y, x % y
return x
def lcm(x, y):
return (x*y)//(gcd(x,y))
mod=1000000007
def modInverse(b,m):
g = gcd(b, m)
if (g != 1):
return -1
else:
return pow(b, m - 2, m)
def ceil(x,y):
if x%y==0:
return x//y
else:
return x//y+1
def modu(a,b,m):
a = a % m
inv = modInverse(b,m)
if(inv == -1):
return -999999999
else:
return (inv*a)%m
from math import log,factorial,cos,tan,sin,radians,floor,log2
import bisect
from decimal import *
getcontext().prec = 8
abc="abcdefghijklmnopqrstuvwxyz"
pi=3.141592653589793238
def gcd1(a):
if len(a) == 1:
return a[0]
ans = a[0]
for i in range(1,len(a)):
ans = gcd(ans,a[i])
return ans
def main():
for _ in range(1):
n=ii()
a=li()
a.sort()
f=[0]*n
ans=0
for i in range(n):
if f[i]:
continue
f[i]=1
ans+=1
p=1
for j in range(i+1,n):
if a[j]>=p and f[j]==0:
f[j]=1
p+=1
print(ans)
# 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")
def print(*args, **kwargs):
"""Prints the values to a stream, or to sys.stdout by default."""
sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
at_start = True
for x in args:
if not at_start:
file.write(sep)
file.write(str(x))
at_start = False
file.write(kwargs.pop("end", "\n"))
if kwargs.pop("flush", False):
file.flush()
if sys.version_info[0] < 3:
sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
else:
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# endregion
if __name__ == "__main__":
#read()
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.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.*;
public class ForcesC {
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(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;
}
}
static long mod = (long)(1e9+7);
public static void main(String[] args) {
// TODO Auto-generated method stub
FastReader sc = new FastReader();
int n = sc.nextInt();
int[] a = new int[n];
TreeMap<Integer, Integer> map = new TreeMap<>();
for (int i = 0; i < n; i++) {
a[i] = sc.nextInt();
if(map.containsKey(a[i]))
map.put(a[i],map.get(a[i])+1);
else map.put(a[i], 1);
}
int ans = 0;
while ( !map.isEmpty() ) {
ans++;
int x = map.firstKey();
delete(map,x);
int count = 1;
while ( !map.isEmpty() ) {
Integer next = map.ceilingKey(count);
if ( next == null ) break;
count++;
delete(map, next);
}
}
System.out.println(ans);
}
static void delete(Map<Integer, Integer> map, int key) {
if ( map.get(key) != 1 )
map.put( key, map.get(key) - 1 );
else
map.remove(key);
}
static class Pair {
int x;
int y;
Pair(int x,int y){
this.x = x;
this.y = y;
}
}
} | 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 = [*map(int,input().split())]
l.sort()
spen = 0
ans = 0
while(spen < n):
x = 0
for i in range(n):
if(l[i] >= x):
x += 1
spen += 1
l[i] = -10**3
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.util.*;
public class A {
public static void main(String... args) {
final Scanner sc = new Scanner(System.in);
final int n = sc.nextInt();
final int[] x = new int[n];
for (int i = 0; i < n; i++)
x[i] = sc.nextInt();
Arrays.sort(x);
int ans = 0;
int cnt = 0;
for (; cnt < n; ans++)
for (int i = 0, h = 0; i < n; i++)
if (h <= x[i]) {
x[i] = -1;
cnt++;
h++;
}
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 a[105], h[105], n;
int sum = 1;
int main() {
scanf("%d", &n);
for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
sort(a + 1, a + n + 1);
h[1] = 1;
for (int i = 2; i <= n; ++i) {
sort(h + 1, h + sum + 1);
if (a[i] < h[1]) {
++sum;
h[sum] = 1;
} else
++h[1];
}
printf("%d", 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 | import java.io.BufferedInputStream;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;
public class Main {
public Scanner cin=new Scanner(new BufferedInputStream(System.in));
public int n;
public int a[] = new int[200];
public int b[] = new int[200];
public List list = null;
public void solve() {
int m = 0;
list = new ArrayList();
for (int i = 0; i < n; i++) {
a[0] = 0;
int x = cin.nextInt();
list.add(x);
}
Collections.sort(list);
for (int i = 0; i < n; i++) {
boolean find = false;
int v = (Integer)list.get(i);
for (int j = 0; j <= m; j++) {
int size = a[j];
if (v >= size) {
a[j]++;
b[j] = v;
find = true;
break;
}
}
if (!find) {
m++;
a[m] = 1;
b[m] = v;
}
}
System.out.println(m+1);
}
public void acm() {
while (cin.hasNext()) {
n = cin.nextInt();
solve();
}
}
public static void main(String args[]) {
Main main = new Main();
main.acm();
}
}
| 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.*;
import java.math.*;
public class Main{
public static void main(String args[]) throws Exception{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
int n = Integer.parseInt(br.readLine());
int ar[] = new int[n];
int pred[] = new int[n];
int cur[] = new int[n];
String[] s = br.readLine().split(" ");
HashSet<Integer> set = new HashSet<Integer>();
for(int i = 0 ; i < n ; i++){
ar[i] = Integer.parseInt(s[i]);
}
Arrays.sort(ar);
for(int i = 0 ; i < n ; i++) pred[i] = i;
for(int i = 0 ; i < n ; i++){
for(int j = i + 1 ; j < n ; j++){
if(cur[j] + cur[i] + 1 <= ar[j] && pred[j] == j){
cur[j] = cur[i] + 1 ;
pred[j] = pred[i];
break;
}
}
}
for(int i = 0 ; i < n ; i++){
set.add(pred[i]);
}
System.out.println(set.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 exists[11111];
vector<int> v;
int N, i, j;
int main() {
scanf("%d", &N);
v.resize(N);
for (i = 0; i < N; i++) scanf("%d", &(v[i]));
sort(v.begin(), v.end());
exists[1] = 1;
for (i = 1; i < N; i++) {
for (j = v[i]; j >= 1; j--)
if (exists[j] > 0) break;
if (j >= 1) {
exists[j]--;
exists[j + 1]++;
} else
exists[1]++;
}
for (i = 1, j = 0; i <= N; i++) j += exists[i];
printf("%d\n", j);
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 | input();print(1+max(x//-~f for x,f in enumerate(sorted(map(int,input().split())))))
# Made By Mostafa_Khaled | 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;
const long long dx[4] = {-1, 0, 1, 0};
const long long dy[4] = {0, -1, 0, 1};
const long long dxx[] = {1, 1, 0, -1, -1, -1, 0, 1};
const long long dyy[] = {0, 1, 1, 1, 0, -1, -1, -1};
void err(istream_iterator<string> it) {}
template <typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
cerr << *it << " = " << a << "\n";
err(++it, args...);
}
long long gcd(long long a, long long b) {
if (!b) return a;
return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return (a * b) / gcd(a, b); }
long long modexpo(long long x, long long n, long long M) {
if (n == 0)
return 1;
else if (n % 2 == 0)
return modexpo((x * x) % M, n / 2, M);
else
return (x * modexpo((x * x) % M, (n - 1) / 2, M)) % M;
}
long long bexpo(long long x, long long n) {
if (n == 0)
return 1;
else if (n % 2 == 0)
return bexpo(x * x, n / 2);
else
return x * bexpo(x * x, (n - 1) / 2);
}
bool isPrime(long long n) {
if (n <= 1) return false;
if (n <= 3) return true;
if (n % 2 == 0 || n % 3 == 0) return false;
for (long long i = 5; i * i <= n; i = i + 6)
if (n % i == 0 || n % (i + 2) == 0) return false;
return true;
}
const long long mod = 1e9 + 7;
const long long N = 4e5 + 5;
const long long INF = 1e18;
void solve() {
long long n;
cin >> n;
;
vector<long long> a(n);
for (auto &i : a) cin >> i;
;
sort(a.begin(), a.end());
long long count = 0, pile = 0;
bool check[n];
memset(check, false, sizeof(check));
while (count < n) {
long long last = 0;
pile++;
for (long long i = 0; i < a.size(); i++) {
if (!check[i] && last <= a[i]) {
check[i] = true;
last++;
count++;
}
}
}
cout << pile << "\n";
;
}
int32_t main() {
long long t;
t = 1;
while (t--) {
solve();
}
}
| 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 heapq
import sys
input = sys.stdin.readline
for _ in range(1):
n=int(input())
arr=[int(x) for x in input().split()]
arr.sort()
temp=[]
for i in arr:
f=False
#print(temp)
for k in range(len(temp)):
if temp[k]<=i and i!=0:
f=True
temp[k]+=1
break
if f==False:
temp.append(1)
print(len(temp))
#print(temp)
| 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.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.TreeSet;
public class Task {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
InputReader in = new InputReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
TaskA s = new TaskA();
s.solve(in, out);
out.close();
}
}
class TaskA {
public void solve( InputReader in, PrintWriter out) {
int n=in.nextInt();
TreeSet<Strength> set=new TreeSet<Strength>();
for(int i=0;i<n;i++){
int t=in.nextInt();
Strength s=set.ceiling(new Strength(t, 0));
if(s!=null && s.val==t){
s.cnt++;
}else{
s=new Strength(t, 1);
set.add(s);
}
}
int ans=0;
while(set.size()>0){
ans++;
for(int i=0;i<n;i++){
Strength s=set.ceiling(new Strength(i, 0));
if(s!=null){
if(s.cnt==1){
set.remove(s);
}else{
s.cnt--;
}
}else{
break;
}
}
}
out.println(ans);
}
}
class Strength implements Comparable<Strength>{
int val;
int cnt;
@Override
public int compareTo(Strength o) {
return val-o.val;
}
public Strength(int val, int cnt) {
super();
this.val = val;
this.cnt = cnt;
}
}
class Problem implements Comparable<Problem>{
int b;
int index;
@Override
public int compareTo(Problem o) {
if(b==o.b){
return index-o.index;
}else{
return b-o.b;
}
}
public Problem(int b, int index) {
super();
this.b = b;
this.index = index;
}
}
class InputReader {
private BufferedReader reader;
private 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 String nextLine() {
try {
return reader.readLine();
} catch (IOException e) {
throw new RuntimeException(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;
int is_possible(vector<int> &strength, int no_of_piles) {
priority_queue<int> pile_tops;
int box_ptr = strength.size() - 1;
for (int i = 1; i <= no_of_piles; i++) pile_tops.push(strength[box_ptr--]);
while (box_ptr >= 0) {
int strongest_pile = pile_tops.top();
pile_tops.pop();
if (strongest_pile == 0) return false;
int next_box = strength[box_ptr];
pile_tops.push(min(strongest_pile - 1, next_box));
box_ptr--;
}
return true;
}
int main() {
int no_of_boxes;
scanf("%d", &no_of_boxes);
vector<int> strength(no_of_boxes);
for (int i = 0; i < no_of_boxes; i++) scanf("%d", &strength[i]);
sort((strength).begin(), (strength).end());
int left = 1, right = no_of_boxes, answer;
while (left <= right) {
int mid = (left + right) >> 1;
if (is_possible(strength, mid)) {
if (mid == 1 || !is_possible(strength, mid - 1)) {
answer = mid;
break;
} else {
right = mid - 1;
}
} else {
left = mid + 1;
}
}
printf("%d", answer);
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 java.lang.*;
public class A {
public static void main(String[] args) {
FastReader in = new FastReader();
int n = in.nextInt();
int[] arr = in.readArray(n);
Arrays.sort(arr);
boolean[] used = new boolean[n];
int ans = 0;
for(int i=0;i<n;i++) {
if(used[i]) continue;
ans++;
int curr =1;
used[i] = true;
for(int j=i+1;j<n;j++) {
if(!used[j]&&arr[j]>=curr) {
// curr = arr[j];
curr++;
used[j] = true;
}
}
}
System.out.println(ans);
}
static final Random random=new Random();
// static void ruffleSort(Pair[] a) {
// int n=a.length;//shuffle, then sort
// for (int i=0; i<n; i++) {
// int oi=random.nextInt(n);
// Pair temp=a[oi];
// a[oi]=a[i]; a[i]=temp;
// }
// Arrays.sort(a);
// }
static void ruffleSort(int[] a) {
int n=a.length;//shuffle, then sort
for (int i=0; i<n; i++) {
int oi=random.nextInt(n), temp=a[oi];
a[oi]=a[i]; a[i]=temp;
}
Arrays.sort(a);
}
static void ruffleSort(char[] a) {
int n=a.length;//shuffle, then sort
for (int i=0; i<n; i++) {
int oi=random.nextInt(n);
char temp=a[oi];
a[oi]=a[i]; a[i]=temp;
}
Arrays.sort(a);
}
static class FastReader
{
BufferedReader br;
StringTokenizer st;
public FastReader()
{
br = new BufferedReader(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[] readArray(int n) {
int[] a=new int[n];
for (int i=0; i<n; i++) a[i]=nextInt();
return a;
}
}
}
//class Pair implements Comparable<Pair>{
// int a;
// int b;
// public Pair(int a, int b) {
// this.a = a;
// this.b = b;
// }
// public int compareTo(Pair o) {
// if(this.a==o.a)
// return this.b - o.b;
// return this.a - o.a;
// }
//} | 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 mop[100000];
void chek(string str) {
for (int i = 0; i < str.size() / 2; i++) {
if (str[i] != str[str.size() - 1 - i])
mop[i] = 1, mop[str.size() - 1 - i] = 1;
}
}
int ch(string str) {
for (int i = 0; i < str.size() / 2; i++) {
if (str[i] != str[str.size() - 1 - i]) return 0;
}
return 1;
}
int main() {
int n, c = 0;
cin >> n;
int arr[n], check[n];
memset(check, 0, sizeof check);
for (int i = 0; i < n; i++) cin >> arr[i];
sort(arr, arr + n);
for (int i = 0; i < n; i++) {
int ch = 0, nn = 0;
for (int j = 0; j < n; j++)
if (!check[j] && arr[j] >= nn) ch = 1, check[j] = 1, nn++;
if (ch) c++;
}
cout << c << 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 | #include <bits/stdc++.h>
using namespace std;
const int MAX = 100 + 10;
const int inf = 0x3f3f3f3f;
int num[MAX], use[MAX];
int main() {
int n, ans, ret;
while (scanf("%d", &n) > 0) {
ans = 0;
int tot = 0;
for (int i = 0; i < n; i++) scanf("%d", &num[i]);
sort(num, num + n);
memset(use, 0, sizeof(use));
while (tot != n) {
int i;
for (i = 0; i < n; i++)
if (!use[i]) {
use[i] = 1;
ans++;
tot++;
break;
}
ret = 1;
for (int j = i + 1; j < n; j++) {
if (!use[j] && num[j] >= ret && num[j] > 0) {
tot++;
use[j] = 1;
ret++;
}
}
}
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 n, a[101];
int main() {
cin >> n;
for (int i = 0; i < n; i++) {
cin >> a[i];
}
sort(a, a + n);
int ans = 0, h, used = 0;
while (used < n) {
ans++;
h = 0;
for (int i = 0; i < n; i++) {
if (a[i] != -1 && a[i] >= h) {
h++;
a[i] = -1;
used++;
}
}
}
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 | #include <bits/stdc++.h>
using namespace std;
int main() {
int n, i, t, piles = 1;
bool flag = true;
cin >> n;
vector<int> s1, s2;
vector<int>::iterator it;
for (i = 0; i < n; i++) {
cin >> t;
s1.push_back(t);
}
sort(s1.begin(), s1.end());
while (flag) {
flag = false;
for (it = s1.begin(), i = 0; it != s1.end();) {
if ((*it) < i) {
flag = true;
s2.push_back(*it);
s1.erase(it);
} else {
it++;
i++;
}
}
if (flag) {
piles += 1;
s1.clear();
s1 = s2;
s2.clear();
}
}
cout << piles;
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() {
int n;
scanf("%d", &n);
int ar[1000];
for (int i = 0; i < n; i++) scanf("%d", &ar[i]);
sort(ar, ar + n);
deque<int> q;
for (int i = 0; i < n; i++) q.push_back(ar[i]);
int ans = 0;
while (!q.empty()) {
ans++;
int tp = 0;
int pos = 0;
while (pos < q.size()) {
int f = q[pos];
if (tp <= f) {
tp++;
q.erase(q.begin() + pos, q.begin() + pos + 1);
} else
pos++;
}
}
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 | #/usr/bin/env python2
n = int(raw_input())
arr = [int(x) for x in raw_input().split(" ")]
arr.sort()
r = []
for x in arr:
if x == 0:
r.append(1)
continue
f = False
for i in xrange(len(r)):
if r[i] <= x:
r[i] = r[i]+1
f = True
break
if not f:
r.append(1)
print len(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 | #include <bits/stdc++.h>
using namespace std;
long long MOD = 1e9 + 7;
std::vector<long long> se(std::vector<long long> v) {
std::vector<long long> v1;
for (long long i = 0; i < v.size(); ++i) {
if (v1.empty() || v1.back() != v[i]) {
v1.push_back(v[i]);
}
}
return v1;
}
void prinvector(std::vector<long long> v) {
for (long long i = 0; i < v.size(); ++i) {
cout << v[i] << " ";
}
cout << " " << endl;
}
void prinarray(long long a[], long long n) {
for (long long i = 0; i < n; ++i) {
cout << a[i] << " ";
}
cout << " " << endl;
}
void p1(long long x) { cout << x << endl; }
void p2(long long x) { cout << x << " "; }
void p3(long long x) { cout << x; }
void solve() {
long long n;
cin >> n;
std::vector<long long> v[100];
std::vector<long long> a;
for (long long i = 0; i < n; ++i) {
long long x;
cin >> x;
a.push_back(x);
}
sort(a.begin(), a.end());
for (long long i = 0; i < n; ++i) {
for (long long j = 0; j < 100; ++j) {
if (v[j].empty() || v[j].size() <= a[i]) {
v[j].push_back(a[i]);
break;
}
}
}
long long s = 0;
for (long long i = 0; i < 100; ++i) {
n = v[i].size();
s += min((long long)1, n);
}
cout << s << endl;
}
int32_t main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.precision(10);
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 | import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Random;
import java.util.StringTokenizer;
public class Main {
static final Random random = new Random();
static PrintWriter out = new PrintWriter(System.out);
public static void main(String[] args) throws FileNotFoundException {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] freq = new int[101];
for (int i = 0; i < n; i++)
freq[sc.nextInt()]++;
int piles = 0;
for (;;) {
int min = 101;
for (int i = 0; i <= 100; i++)if (freq[i] > 0 && i < min)min = i;
if (min == 101)
break;
piles++;
int boxes = 1;
int ptr = 1;
freq[min]--;
while (ptr <= 100) {
if (freq[ptr] > 0 && ptr >= boxes) {
boxes++;
freq[ptr]--;
} else
ptr++;
}
}
out.println(piles);
out.flush();
}
static void Arrayssort(int[] a) {
int n = a.length;// shuffle, then sort
for (int i = 0; i < n; i++) {
int oi = random.nextInt(n);
int temp = a[oi];
a[oi] = a[i];
a[i] = temp;
}
java.util.Arrays.sort(a);
}
private static class Scanner {
public BufferedReader reader;
public StringTokenizer st;
public Scanner(InputStream file) throws FileNotFoundException {
reader = new BufferedReader(new InputStreamReader(file));
st = null;
}
public String next() {
while (st == null || !st.hasMoreTokens()) {
try {
String line = reader.readLine();
if (line == null)
return null;
st = new StringTokenizer(line);
} catch (Exception e) {
throw (new RuntimeException());
}
}
return st.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
return Double.parseDouble(next());
}
public String nextLine() throws IOException {
return reader.readLine();
}
}
} | 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, t[102];
bool ok(int a) {
vector<int> b(a + 1, 1000);
for (int i = 0; i < n; i++) {
if (!b[i % a]) return 0;
b[i % a] = min(b[i % a] - 1, t[i]);
}
return 1;
}
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d", &t[i]);
sort(t, t + n, greater<int>());
for (int i = 1; i <= n; i++) {
if (ok(i)) {
printf("%d", i);
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 FoxAndBoxAccumulation {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
List<Integer> box = new ArrayList<Integer>();
for (int i = 0; i < n; i++) {
box.add(in.nextInt());
}
Collections.sort(box);
int count = 0;
while (true) {
if (box.isEmpty()) {
System.out.println(count);
break;
}
boolean found = false;
int curr = 1;
count++;
box.remove(0);
for (int i = 0; i < box.size();) {
if (box.get(i) >= curr) {
found = true;
curr++;
box.remove(i);
} else {
i++;
}
}
if (!found) {
System.out.println(count + box.size());
break;
}
}
in.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 | import java.io.InputStreamReader;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.InputStream;
import java.util.Arrays;
/**
* 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);
try (PrintWriter out = new PrintWriter(outputStream)) {
TaskB solver = new TaskB();
solver.solve(1, in, out);
}
}
}
class TaskB {
public void solve(int testNumber, InputReader in, PrintWriter out) {
int n = in.nextInt();
int a[] = new int[n];
boolean ok = false;
boolean check[] = new boolean[n];
int sum = 0;
int zero = 0;
for(int i = 0; i < n; ++i){
a[i] = in.nextInt();
}
Arrays.sort(a);
while(!ok){
int count = 0;
boolean bool = false;
for(int i = 0; i < n; ++i){
if(!check[i]){
if(count <= a[i]){
count++;
check[i] = true;
}else{
bool = true;
}
}
}
sum++;
if(!bool){
ok = true;
}
}
out.println(sum);
}
}
class InputReader {
private final BufferedReader reader;
private StringTokenizer tokenizer;
public InputReader(InputStream stream) {
reader = new BufferedReader(new InputStreamReader(stream));
tokenizer = null;
}
public String nextLine() {
try {
return reader.readLine();
} catch (IOException e) {
throw new RuntimeException(e);
}
}
public String next() {
while (tokenizer == null || !tokenizer.hasMoreTokens()) {
tokenizer = new StringTokenizer(nextLine());
}
return tokenizer.nextToken();
}
public int nextInt() {
return Integer.parseInt(next());
}
public long nextLong() {
return Long.parseLong(next());
}
public double nextDouble() {
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>
#pragma comment(linker, "/STACK:16777216")
#pragma warning(disable : 4786)
using namespace std;
template <class T>
inline T MAX(T a, T b) {
return a > b ? a : b;
}
template <class T>
inline T MIN(T a, T b) {
return a < b ? a : b;
}
template <class T>
inline void SWAP(T &a, T &b) {
a = a ^ b;
b = a ^ b;
a = a ^ b;
}
template <class T, class T1>
inline void Reverse(T1 A[], T i, T j) {
for (; i < j; i++, j--) SWAP(A[i], A[j]);
}
template <class T>
inline T fAbs(T a) {
return a < 0 ? a * (-1) : a;
}
const int sz = 1e2 + 10;
const int inf = 1e31 - 1;
const double PI = 2 * acos(0.0);
const double eps = 1e-9;
int arr[sz];
int vis[sz];
int main() {
int n;
scanf("%d", &n);
int i;
for (i = 0; i < n; i++) {
scanf("%d", &arr[i]);
}
sort(arr, arr + n);
int cnt = 0, tmp, pile = 0;
while (true) {
cnt = 0;
for (i = 0; i < n; i++) {
if (!vis[i]) {
tmp = arr[i];
break;
}
}
if (i == n) break;
pile++;
vis[i] = 1;
cnt = 1;
for (i = 0; i < n; i++) {
if (!vis[i]) {
if (arr[i] >= tmp && arr[i] >= cnt && arr[i] != 0) {
tmp = arr[i];
cnt++;
vis[i] = 1;
}
}
}
}
printf("%d\n", pile);
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 FoxAndBoxAccumulation {
Scanner in;
int n;
List<Integer> list = new ArrayList<Integer>(101);
int[] nr = new int[101];
int count=0;
public static void main(String[] args) {
new FoxAndBoxAccumulation();
}
public FoxAndBoxAccumulation() {
int number;
boolean put;
in=new Scanner(System.in);
n=in.nextInt();
// reads the end of line
in.nextLine();
for (int i=0;i<n;++i) {
number=in.nextInt();
list.add(number);
}
Collections.sort(list);
for (Integer x : list) {
put=false;
for (int i=0;i<count;++i) {
if (x>=nr[i]) {
nr[i]++;
put=true;
break;
}
}
if (!put) {
nr[count++]=1;
}
}
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 | #include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL);
int n, i, j, flag;
cin >> n;
int arr[100], a[n];
for (i = 0; i < n; i++) cin >> a[i];
sort(a, a + n);
arr[0] = 1;
int c = 1;
for (i = 1; i < n; i++) {
flag = 0;
for (j = 0; j < c; j++) {
if (arr[j] <= a[i]) {
arr[j]++;
flag = 1;
break;
}
}
if (flag == 0) {
arr[c] = 1;
c++;
}
}
cout << c << "\n";
}
| 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()
m = sorted(map(int, raw_input().strip().split()))
kor = [0]
for i in xrange(n):
if m[i]<min(kor):
kor+=[1]
else:
kor[kor.index(min(kor))]+=1
print len(kor) | 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 check {
static boolean DEBUG_FLAG = false;
int INF = (int)1e9;
long MOD = 1000000007;
static void debug(String s) {
if(DEBUG_FLAG) {
System.out.print(s);
}
}
void solve(InputReader in, PrintWriter out) throws IOException {
int n = in.nextInt();
int[] a = new int[n];
for(int i=0; i<n; i++) {
a[i] = in.nextInt();
}
Arrays.sort(a);
int rs = 0, c = 0;
while(c<n) {
rs++;
int h = 0;
for(int i=0; i<n; i++) {
if(a[i]>=h) {
a[i] = -1;
c++;
h++;
}
}
}
out.println(rs);
}
public static void main(String[] args) throws IOException {
if(args.length>0 && args[0].equalsIgnoreCase("d")) {
DEBUG_FLAG = true;
}
InputReader in = new InputReader();
PrintWriter out = new PrintWriter(System.out);
int t = 1;//in.nextInt();
long start = System.nanoTime();
while(t-- >0) {
new check().solve(in, out);
}
long end = System.nanoTime();
debug("\nTime: " + (end-start)/1e6 + " \n\n");
out.close();
}
static class InputReader {
static BufferedReader br;
static StringTokenizer st;
public InputReader() {
br = new BufferedReader(new InputStreamReader(System.in));
}
String next() {
while (st == null || !st.hasMoreTokens()) {
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());
}
}
} | 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())
temparr = input()
temparr = temparr.split()
arr = []
for i in temparr:
arr.append(int(i))
arr = sorted(arr)
revarr = arr[::-1]
mins = len(arr)
left = 0
right = mins
#print(revarr)
while left <= right:
temp = []
flag = 0
mid = (left + right ) // 2
nexts = 0
index = 0
for i in range(mid):
temp.append( [revarr[i], 0, revarr[i] ] )
index += 1
#print(temp)
flag = 0
newindex = -1
for i in range(index, n):
flag = 0
newindex += 1
for k in range(mid):
j = ( newindex + k ) % mid
if temp[j][0] > temp[j][1] and revarr[i] < temp[j][0] and temp[j][2] >= 1:
flag = 1
temp[j][0] = revarr[i]
temp[j][1] = 0
temp[j][2] -= 1
elif temp[j][0] > temp[j][1] and revarr[i] == temp[j][0] and temp[j][2] >= 1:
flag = 1
temp[j][1] += 1
temp[j][2] -= 1
#print(temp)
if flag == 1:
break
#print("i " + str(i) +" flag " + str(flag))
if flag == 0 :
break
if flag == 0:
left = mid + 1
else:
mins = min(mid, mins)
right = mid - 1
print(mins)
#[10, 2, 2, 1, 1, 1, 0, 0, 0]
| 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 n;
int a[110];
int b[110][110];
vector<int> p[10010];
int main() {
for (int i = 0; i < 10010; i++) p[i].clear();
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
sort(a + 1, a + n + 1);
for (int i = 1; i <= n; i++) p[i].push_back(a[i]);
for (int i = 1; i <= n; i++) {
for (int j = i + 1; j <= n; j++) {
bool jud = true;
for (int k = 0; k < (int)p[j].size(); k++) {
if (p[j][k] < (int)p[i].size() + (int)p[j].size() - k - 1) jud = false;
if (!jud) break;
}
if (jud) {
for (int k = 0; k < (int)p[i].size(); k++) p[j].push_back(p[i][k]);
p[i].clear();
}
}
}
int res = 0;
for (int i = 1; i <= n; i++) {
if ((int)p[i].size() != 0) res++;
}
printf("%d\n", res);
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() {
long n;
while (cin >> n) {
long i, ar[2001] = {0}, a, mx = 0, res = 0, f = 0, col[2001] = {0},
flag = 1;
for (int i = 0, _n = n; i < _n; i++) cin >> ar[i];
sort(ar, ar + n);
while (1) {
f = 0;
mx = 0;
for (int i = 0; i < n; i++) {
if (col[i]) continue;
f = 1;
if (ar[i] >= mx) {
mx++;
col[i] = 1;
}
}
if (f) {
res++;
} else
break;
}
cout << res << 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
from collections import defaultdict, Counter
from math import sin, cos, asin, acos, tan, atan, pi
sys.setrecursionlimit(10 ** 6)
def pyes_no(condition, yes = "YES", no = "NO", none = "-1") :
if condition == None:
print (none)
elif condition :
print (yes)
else :
print (no)
def plist(a, s = ' ') :
print (s.join(map(str, a)))
def rint() :
return int(sys.stdin.readline())
def rstr() :
return sys.stdin.readline().strip()
def rints() :
return map(int, sys.stdin.readline().split())
def rfield(n, m = None) :
if m == None :
m = n
field = []
for i in xrange(n) :
chars = sys.stdin.readline().strip()
assert(len(chars) == m)
field.append(chars)
return field
def pfield(field, separator = '') :
print ('\n'.join(map(lambda x: separator.join(x), field)))
def check_field_equal(field, i, j, value) :
if i >= 0 and i < len(field) and j >= 0 and j < len(field[i]) :
return value == field[i][j]
return None
def digits(x, p) :
digits = []
while x > 0 :
digits.append(x % p)
x //= p
return digits[::-1]
def undigits(x, p) :
value = 0
for d in x :
value *= p
value += d
return value
def modpower(a, n, mod) :
r = a ** (n % 2)
if n > 1 :
r *= modpower(a, n // 2, mod) ** 2
return r % mod
def gcd(a, b) :
if a > b :
a, b = b, a
while a > 0 :
a, b = b % a, a
return b
def vector_distance(a, b) :
diff = vector_diff(a, b)
return scalar_product(diff, diff) ** 0.5
def vector_inverse(v) :
r = [-x for x in v]
return tuple(r)
def vector_diff(a, b) :
return vector_sum(a, vector_inverse(b))
def vector_sum(a, b) :
r = [c1 + c2 for c1, c2 in zip(a, b)]
return tuple(r)
def scalar_product(a, b) :
r = 0
for c1, c2 in zip(a, b) :
r += c1 * c2
return r
def check_rectangle(points) :
assert(len(points) == 4)
A, B, C, D = points
for A1, A2, A3, A4 in [
(A, B, C, D),
(A, C, B, D),
(A, B, D, C),
(A, C, D, B),
(A, D, B, C),
(A, D, C, B),
] :
sides = (
vector_diff(A1, A2),
vector_diff(A2, A3),
vector_diff(A3, A4),
vector_diff(A4, A1),
)
if all(scalar_product(s1, s2) == 0 for s1, s2 in zip(sides, sides[1:])) :
return True
return False
def check_square(points) :
if not check_rectangle(points) :
return False
A, B, C, D = points
for A1, A2, A3, A4 in [
(A, B, C, D),
(A, C, B, D),
(A, B, D, C),
(A, C, D, B),
(A, D, B, C),
(A, D, C, B),
] :
side_lengths = [
(first[0] - next[0]) ** 2 + (first[1] - next[1]) ** 2 for first, next in zip([A1, A2, A3, A4], [A2, A3, A4, A1])
]
if len(set(side_lengths)) == 1 :
return True
return False
def check_right(p) :
# Check if there are same points
for a, b in [
(p[0], p[1]),
(p[0], p[2]),
(p[1], p[2]),
] :
if a[0] == b[0] and a[1] == b[1] :
return False
a, b, c = p
a, b, c = vector_diff(a, b), vector_diff(b, c), vector_diff(c, a)
return scalar_product(a, b) * scalar_product(a, c) * scalar_product(b, c) == 0
def modmatrixproduct(a, b, mod) :
n, m1 = len(a), len(a[0])
m2, k = len(b), len(b[0])
assert(m1 == m2)
m = m1
r = [[0] * k for i in range(n)]
for i in range(n) :
for j in range(k) :
for l in range(m) :
r[i][j] += a[i][l] * b[l][j]
r[i][j] %= mod
return r
def modmatrixpower(a, n, mod) :
magic = 2
for m in [2, 3, 5, 7] :
if n % m == 0 :
magic = m
break
r = None
if n < magic :
r = a
n -= 1
else :
s = modmatrixpower(a, n // magic, mod)
r = s
for i in range(magic - 1) :
r = modmatrixproduct(r, s, mod)
for i in range(n % magic) :
r = modmatrixproduct(r, a, mod)
return r
n = rint()
x = sorted(rints())
count = 1
stopka_min = 0
i = 0
while x :
if i >= len(x) :
count += 1
i = 0
stopka_min = 0
while i < len(x) and x[i] >= stopka_min :
x.pop(i)
stopka_min += 1
i += 1
print count
| 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, a[105], l, r, mid, ans;
bool ok;
int main() {
ios::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);
l = 1;
r = n;
while (l <= r) {
mid = (l + r) / 2;
ok = true;
for (int i = 1; i <= n; i++) {
if (a[i] < (i - 1) / mid) ok = false;
}
if (ok) {
r = mid - 1;
ans = mid;
} else
l = mid + 1;
}
cout << ans << "\n";
}
| 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 Main {public static void main(String[] args) throws Exception { new Solve(); }}
class Solve { public Solve() throws Exception {solve(); }
static BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
static StringTokenizer st = new StringTokenizer("");
void solve() throws Exception {
int n = NI();
int d[] = new int[101];
int b[] = new int [n];
boolean c[] = new boolean[n];
int t, cnt = 0;
for (int i = 0; i < n; i++) {
t = NI();
d[t]++;
b[i] = t;
}
Arrays.sort(d);
Arrays.sort(b);
int res = 0, wt = n;
cnt++;
for (int i = 0; i < n; i++) {
if (c[i])
continue;
cnt = 1;
for (int j = i + 1; j < n ; j++) {
if (c[j])
continue;
if (b[j] >= cnt) {
c[j] = true;
cnt++;
}
}
res++;
}
System.out.println(res);
}
class Pair {
String s;
int i;
public Pair(String s) {
this.s = s;
i = 1;
}
}
int min(int i1, int i2) {
return i1 < i2 ? i1 : i2;
}
long min(long i1, long i2) {
return i1 < i2 ? i1 : i2;
}
int max(int i1, int i2) {
return i1 > i2 ? i1 : i2;
}
long max(long i1, long i2) {
return i1 > i2 ? i1 : i2;
}
public String NS() throws Exception {
while(!st.hasMoreTokens())
st = new StringTokenizer(stdin.readLine());
return st.nextToken();
}
public int NI() throws Exception {
return Integer.parseInt(NS());
}
int abs(int x) {
return x < 0 ? -x : x;
}
int ceil(float c) {
return (int)(c + 0.5);
}
} | 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>
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization("unroll-loops")
using namespace std;
const int maxn = (long long int)1e9 + 7;
const double pi = acos(-1.0);
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
;
int n;
cin >> n;
int arr[n + 3];
for (int i = 0; i < n; i++) cin >> arr[i];
sort(arr, arr + n);
int ans = 1;
int _ = 0;
while (_ < n) {
int i = 0, cnt = 0;
for (i = 0; i < n; i++) {
if (arr[i] > -1) {
cnt++;
arr[i] = -1;
_++;
break;
}
}
if (_ >= n) break;
for (; i < n; i++) {
if (arr[i] >= cnt) {
arr[i] = -1;
_++;
cnt++;
}
}
if (_ >= n) break;
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 | def b(a, la, n):
for i in range(n):
b = a[i::n]
ll = (la - i + n - 1) // n
for j in range(ll):
if b[j] < ll - j - 1:
return False
return True
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse = True)
l, r = 1, n
if b(a, n, l):
print(l)
exit()
if b(a, n, r - 1) == False:
print(r)
exit()
while l + 1 < r:
h = (l + r) // 2
q = b(a, n, h)
if q:
r = h
else:
l = h
print(r) | 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 div2_228_C implements Runnable {
final boolean ONLINE_JUDGE = System.getProperty("ONLINE_JUDGE") != null;
BufferedReader in;
PrintWriter out;
StringTokenizer tok = new StringTokenizer("");
public static void main(String[] args) {
new Thread(null, new div2_228_C(), "", 128 * (1L << 20)).start();
}
void init() throws FileNotFoundException {
Locale.setDefault(Locale.US);
if (ONLINE_JUDGE) {
in = new BufferedReader(new InputStreamReader(System.in));
out = new PrintWriter(System.out);
} else {
in = new BufferedReader(new FileReader("input.txt"));
out = new PrintWriter("output.txt");
}
}
long timeBegin, timeEnd;
void time() {
timeEnd = System.currentTimeMillis();
System.err.println("Time = " + (timeEnd - timeBegin));
}
public void run() {
try {
timeBegin = System.currentTimeMillis();
init();
solve();
out.close();
time();
} catch (Exception e) {
e.printStackTrace(System.err);
System.exit(-1);
}
}
String readString() throws IOException {
while (!tok.hasMoreTokens()) {
try {
tok = new StringTokenizer(in.readLine());
} catch (Exception e) {
return null;
}
}
return tok.nextToken();
}
String readString(String s) throws IOException {
while (!tok.hasMoreTokens()) {
try {
tok = new StringTokenizer(in.readLine(), s + "\n \t");
} catch (Exception e) {
return null;
}
}
return tok.nextToken();
}
int readInt() throws IOException {
return Integer.parseInt(readString());
}
int readInt(String s) throws IOException {
return Integer.parseInt(readString(s));
}
void solve() throws IOException {
int n = readInt();
int src[] = new int[n];
boolean available[] = new boolean[n];
for (int i = 0; i < n; i++){
src[i] = readInt();
available[i]=true;
}
Arrays.sort(src);
System.err.println(Arrays.toString(src));
int rez = 0;
for (int i = 0; i < n; i++) {
if(!available[i])continue;
int sum = 0;
for(int j=i;j<n;j++){
if(!available[j]){
continue;
}
if(src[j]>=sum){
available[j]=false;
sum++;
}
}
rez++;
}
out.print(rez);
}
}
| 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 C1
{
public static LinkedList<Integer> nums;
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
int n = Integer.parseInt(br.readLine());
StringTokenizer st = new StringTokenizer(br.readLine());
nums = new LinkedList<Integer>();
for(int i = 0; i < n; i++)
nums.add(Integer.parseInt(st.nextToken()));
Collections.sort(nums);
int ans = 0;
while(!nums.isEmpty())
{
Integer ceil = -1;
int used = 0;
while((ceil = ceiling(used)) != null)
{
nums.remove(ceil);
used++;
}
ans++;
}
pw.println(ans);
br.close(); pw.close(); System.exit(0);
}
public static Integer ceiling(int start)
{
if(nums.isEmpty())
return null;
int index = 0;
while(index < nums.size() && nums.get(index) < start)
index++;
return index == nums.size() ? null : nums.get(index);
}
} | 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;
template <class T>
void findMax(T &m, T x) {
m = m > x ? m : x;
}
template <class T>
void findMin(T &m, T x) {
m = m < x ? m : x;
}
const double pi = acos(-1);
int main() {
unsigned int n, i, j;
scanf("%d", &n);
int a[n];
for (i = 0; i < n; i++) scanf("%d", a + i);
sort(a, a + n);
vector<int> s;
bool flag;
for (i = 0; i < n; i++) {
flag = false;
for (j = 0; j < s.size(); j++) {
if (a[i] >= s[j]) {
s[j]++;
flag = true;
break;
}
}
if (!flag) {
s.push_back(1);
}
}
printf("%d", (int)s.size());
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 Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
(new Solver()).solve(in, System.out);
}
}
class Solver {
public void solve(Scanner in, PrintStream out) {
int n = in.nextInt();
int[] x = new int[n];
in.nextLine();
for(int i = 0;i<n;i++){
x[i] = in.nextInt();
}
Arrays.sort(x);
for(int i = 1;i<=n;i++) {
int[] d = new int[i];
boolean isFail = false;
for(int j = 0;j<n;j++) {
if(d[j%i] > x[j])
isFail = true;
else
++d[j%i];
}
if(!isFail) {
out.println(i);
return;
}
}
}
}
| 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 INF = 0x3f3f3f3f;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2")
bool comp(int x, int y) { return x > y; }
int32_t main() {
int n;
cin >> n;
vector<vector<int> > a;
a.resize(1);
for (__typeof(n) i = (0) - ((0) > (n)); i != (n) - ((0) > (n));
i += 1 - (((0) > (n)) << 1)) {
int tmp;
cin >> tmp;
a[0].push_back(tmp);
}
for (__typeof(a.size()) i = (0) - ((0) > (a.size()));
i != (a.size()) - ((0) > (a.size()));
i += 1 - (((0) > (a.size())) << 1)) {
sort(begin(a[i]), end(a[i]));
reverse(begin(a[i]), end(a[i]));
for (__typeof(0) j = (a[i].size()) - ((a[i].size()) > (0));
j != (0) - ((a[i].size()) > (0));
j += 1 - (((a[i].size()) > (0)) << 1)) {
if (a[i][j] < (int)a[i].size() - j - 1) {
;
;
if (i == a.size() - 1) a.resize(a.size() + 1);
a.back().push_back(a[i][j]);
a[i].erase(a[i].begin() + j);
}
}
}
cout << a.size() << "\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;
int main() {
long long int n, i, j;
cin >> n;
long long int arr[n];
multiset<long long int> s;
map<long long int, long long int> ans;
for (i = 0; i < n; i++) {
cin >> arr[i];
s.insert(arr[i]);
ans[arr[i]]++;
}
long long int ans2 = 0;
while (s.size() != 0) {
auto itr = s.begin();
long long int count = 1;
ans2++;
s.erase(itr);
itr = s.lower_bound(count);
while (itr != s.end()) {
s.erase(itr);
count++;
itr = s.lower_bound(count);
}
}
cout << ans2;
}
| 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, num[200], tot;
int max(int a, int b) { return a > b ? a : b; }
int main() {
scanf("%d", &n);
tot = n;
for (int i = 1; i <= n; i++) {
int x;
scanf("%d", &x);
num[x] += 1;
}
int zu = 0;
for (int i = 0; i <= 100; i++) {
while (num[i]) {
int now = 0;
now += 1;
num[i] -= 1;
for (int j = i; j <= 100; j++) {
while (num[j] && j >= now) {
num[j] -= 1;
now += 1;
}
}
zu += 1;
}
}
printf("%d", zu);
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 = list(map(int, input().split()))
a.sort()
k = 1
while True:
for i in range(len(a)):
if a[i] < (i//k):
break
else:
print(k)
break
k += 1 | 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;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
int[] t = new int[101];
for (int i = 0; i < n; i++) {
t[sc.nextInt()]++;
}
int currStep = 1;
while (currStep <= 100) {
if (currStep == 0) currStep++;
if (t[currStep] > t[0]) {
t[currStep]--;
t[--currStep]++;
} else {
currStep++;
}
}
System.out.println(t[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.util.Arrays;
import java.util.Scanner;
public class A388 {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int[] arr = new int[n];
for (int i = 0; i < n; ++i) {
arr[i] = in.nextInt();
}
Arrays.sort(arr);
int col = 1;
for (int i = 0; i < n; ++i) {
if (col * arr[i] + col - 1 < i) {
col++;
}
}
System.out.println(col);
}
}
| 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
# n = int(input())
# arr = list(map(int, input().split()))
# arr = sorted(arr, reverse=True)
# i = 0
# c = 0
# while i < n - 1:
# s = sum(arr[i + 1:])
# j = n - 1
# while s >= arr[i]:
# print(i, j)
# s -= arr[j]
# j -= 1
# i = j + 1
# c += 1
# print(c)
n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
k = 0
for i in range(n):
if k * (a[i] + 1) <= i:
k += 1
print(k)
| 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;
bool vis[101];
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;
cin >> n;
int x[n];
for (int i = 0; i < n; i++) cin >> x[i];
sort(x, x + n);
memset(vis, 0, sizeof(vis));
int ans = 0;
for (int i = 0; i < n; i++) {
if (!vis[i]) {
ans++;
int prev = 1;
for (int j = i + 1; j < n; j++) {
if (x[j] >= prev && !vis[j]) {
vis[j] = true;
prev++;
}
}
}
}
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.util.Map.Entry;
public class Main {
public static void main(String[] args) throws IOException {
(new Main()).solve();
}
public Main() {
}
MyReader in = new MyReader();
PrintWriter out = new PrintWriter(System.out);
void solve() throws IOException {
//BufferedReader in = new BufferedReader(new
//InputStreamReader(System.in));
//Scanner in = new Scanner(System.in);
//Scanner in = new Scanner(new FileReader("input.txt"));
//PrintWriter out = new PrintWriter("output.txt");
int n = in.nextInt();
int[] x = new int[n];
for (int i = 0; i < n; i++) {
x[i] = in.nextInt();
}
Arrays.sort(x);
int left = 1;
int right = n;
while (left < right) {
int m = (left + right) / 2;
boolean flag = true;
for (int i = 0; i < n; i += m) {
for (int j = i; j < i + m && j < n; j++) {
if (x[j] < i / m) {
flag = false;
break;
}
}
if (!flag) {
break;
}
}
if (flag) {
right = m;
} else {
left = m + 1;
}
}
out.println(left);
out.close();
}
class MyReader {
private BufferedReader in;
String[] parsed;
int index = 0;
public MyReader() {
in = new BufferedReader(new InputStreamReader(System.in));
}
public int nextInt() throws NumberFormatException, IOException {
if (parsed == null || parsed.length == index) {
read();
}
return Integer.parseInt(parsed[index++]);
}
public long nextLong() throws NumberFormatException, IOException {
if (parsed == null || parsed.length == index) {
read();
}
return Long.parseLong(parsed[index++]);
}
public double nextDouble() throws NumberFormatException, IOException {
if (parsed == null || parsed.length == index) {
read();
}
return Double.parseDouble(parsed[index++]);
}
public String nextString() throws IOException {
if (parsed == null || parsed.length == index) {
read();
}
return parsed[index++];
}
private void read() throws IOException {
parsed = in.readLine().split(" ");
index = 0;
}
public String readLine() throws IOException {
return in.readLine();
}
}
}; | 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())
ar = list(map(int, input().split()))
ar.sort()
a = 1
b = 100
while a < b:
compliant = True
k = (a+b) // 2
for i in range(len(ar)):
if ar[i] < (i//k):
compliant = False
break
if compliant:
b = k
else:
a = k + 1
print(b) | 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.*;
import java.math.*;
import java.io.*;
import java.awt.Point;
import static java.util.Arrays.*;
import static java.lang.Integer.*;
import static java.lang.Double.*;
import static java.lang.Long.*;
import static java.lang.Short.*;
import static java.lang.Math.*;
import static java.math.BigInteger.*;
import static java.util.Collections.*;
public class Main {
private BufferedReader in;
private StringTokenizer st;
private PrintWriter out;
private int n;
private int[] arr;
public void solve() throws Exception {
n = parseInt(in.readLine().trim());
arr = new int[n];
st = new StringTokenizer(in.readLine());
for(int i=0; i<n; i++){
arr[i] = parseInt(st.nextToken());
}
sort(arr);
int ans = 100;
for(int i=1; i<n+1; i++){
boolean canSolve = true;
for(int j=0; j<n; j++){
if(arr[j] < j / i) {
canSolve = false;
break;
}
}
if(canSolve) {
out.println(i);
break;
}
}
}
public Main() {
this.in = new BufferedReader(new InputStreamReader(System.in));
this.out = new PrintWriter(System.out);
}
public void end() {
try {
this.out.flush();
this.out.close();
this.in.close();
} catch (Exception e){
//do nothing then :)
}
}
public static void main(String[] args) throws Exception {
Main solver = new Main();
solver.solve();
solver.end();
}
}
| 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 inf = (int)1e9;
const long long llinf = (long long)3e18;
const int N = (int)1e5 + 111;
const long double PI = (long double)acos(-1);
int main() {
int n, cur, num, ans = 0;
scanf("%d", &n);
vector<int> a(n);
vector<char> us(n, 0);
for (int i = 0; i < n; i++) scanf("%d", &a[i]);
sort(a.begin(), a.end());
for (int i = 0; i < n; i++)
if (us[i] == 0) {
cur = i;
num = 0;
while (cur < n) {
if (us[cur] == 1 || a[cur] < num)
cur++;
else {
num++;
us[cur] = 1;
}
}
ans++;
}
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 A[110], n, ans;
int main() {
cin >> n;
for (int i = 0, x; i < n; ++i) cin >> x, A[x]++;
int nn = n;
while (nn) {
int all(0);
for (int i = 0; i <= 100; i++) {
if (A[i]) {
while (A[i] && all <= i) {
all++;
A[i]--;
nn--;
}
}
}
ans++;
}
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 | //package main;
import java.io.*;
import java.util.*;
import java.awt.Point;
import java.math.BigInteger;
public final class Main {
BufferedReader br;
StringTokenizer stk;
public static void main(String[] args) throws Exception {
new Main().run();
}
{
stk = null;
br = new BufferedReader(new InputStreamReader(System.in));
}
void run() throws Exception {
int n = ni();
int[] a = new int[n];
for(int i=0; i<n; i++) a[i] = ni();
Arrays.sort(a);
for(int i=0, j=n-1; i<j; i++, j--) {
int temp = a[i];
a[i] = a[j];
a[j] = temp;
}
for(int i=1; i<=n; i++) {
if(ok(a, i)) {
pl(i); return;
}
}
}
boolean ok(int[] a, int k) {
List<Integer>[] list = new ArrayList[k];
for(int i=0; i<k; i++) list[i] = new ArrayList<>();
for(int i=0; i<a.length; i++) {
list[i % k].add(a[i]);
}
boolean res = true;
for(List<Integer> pile : list) {
for(int i=0; i<pile.size(); i++) {
int elementsOnTop = pile.size() - i - 1;
if(elementsOnTop > pile.get(i))
res = false;
}
}
return res;
}
//Reader & Writer
String nextToken() throws Exception {
if (stk == null || !stk.hasMoreTokens()) {
stk = new StringTokenizer(br.readLine(), " ");
}
return stk.nextToken();
}
String nt() throws Exception {
return nextToken();
}
String ns() throws Exception {
return br.readLine();
}
int ni() throws Exception {
return Integer.parseInt(nextToken());
}
long nl() throws Exception {
return Long.parseLong(nextToken());
}
double nd() throws Exception {
return Double.parseDouble(nextToken());
}
void p(Object o) {
System.out.print(o);
}
void pl(Object o) {
System.out.println(o);
}
} | 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, a[100], b[100], p = 0;
bool piled;
int main() {
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf(" %d", &a[i]);
sort(a, a + n);
for (int i = 0; i < n; i++) {
piled = false;
for (int j = 0; j < p; j++) {
if (b[j] <= a[i]) {
piled = true;
b[j]++;
break;
}
}
if (!piled) {
b[p++] = 1;
}
}
printf("%d\n", p);
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.util.InputMismatchException;
import java.io.PrintStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.math.BigInteger;
import java.io.InputStream;
/**
* Built using CHelper plug-in
* Actual solution is at the top
* @author karan173
*/
public class Main {
public static void main(String[] args) {
InputStream inputStream = System.in;
OutputStream outputStream = System.out;
FastReader in = new FastReader(inputStream);
PrintWriter out = new PrintWriter(outputStream);
a solver = new a();
solver.solve(1, in, out);
out.close();
}
}
class a
{
public void solve(int testNumber, FastReader in, PrintWriter out)
{
int n = in.ni ();
int cnt[] = new int[101];
Arrays.fill (cnt, 0);
for (int i = 0; i < n; i++)
{
cnt[in.ni ()]++;
}
int pileSize[] = new int[100];
Arrays.fill (pileSize, 0);
for (int i = 0; i <= 100; i++)
{
for (int j = 0; j < 100; j++)
{
//check jth pile feasibility
int remCap = i - pileSize[j];
int reqd = cnt[i];
int take = Math.min (remCap + 1, reqd);
cnt[i] -= take;
pileSize[j] += take;
}
}
int ans = 0;
for (int i = 0; i < 100; i++)
{
if (pileSize[i] > 0)
{
ans++ ;
}
}
out.println (ans);
}
}
class FastReader
{
public InputStream stream;
private byte[] buf = new byte[1024];
private int curChar;
private int numChars;
private SpaceCharFilter filter;
public FastReader(InputStream stream)
{
this.stream = stream;
}
public int read()
{
if (numChars == -1)
{
throw new InputMismatchException ();
}
if (curChar >= numChars)
{
curChar = 0;
try
{
numChars = stream.read (buf);
} catch (IOException e)
{
throw new InputMismatchException ();
}
if (numChars <= 0)
{
return -1;
}
}
return buf[curChar++];
}
public int ni()
{
int c = read ();
while (isSpaceChar (c))
c = read ();
int sgn = 1;
if (c == '-')
{
sgn = -1;
c = read ();
}
int res = 0;
do
{
if (c < '0' || c > '9')
{
throw new InputMismatchException ();
}
res *= 10;
res += c - '0';
c = read ();
} while (!isSpaceChar (c));
return res * sgn;
}
public boolean isSpaceChar(int c)
{
if (filter != null)
{
return filter.isSpaceChar (c);
}
return isWhitespace (c);
}
public static boolean isWhitespace(int c)
{
return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
}
public interface SpaceCharFilter
{
public boolean isSpaceChar(int ch);
}
}
| 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.Arrays;
import java.util.Scanner;
public class PC {
int n;
int A[];
int used[];
public static void main(String[] args){
new PC().go();
}
private void go(){
Scanner in = new Scanner(System.in);
int n = in.nextInt();
A = new int[n];
used = new int[n];
for (int i=0;i<n;i++){
A[i]= in.nextInt();
used[i] = 0;
}
Arrays.sort(A);
int piles = 0;
for (int k=0;k<n;k++){
boolean done = true;
int currentLoad = 0;
for (int i=0;i<n;i++){
if (used[i]==0 && A[i]>=currentLoad){
done = false;
used[i]=1;
currentLoad++;
}
}
if (done) break;
piles++;
}
System.out.println(piles);
}
}
| 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 | # your code goes here
n=input()
A=sorted(map(int,raw_input().split()))
B=[]
for x in A:
for i,y in enumerate(B):
if x>=y:
B[i]+=1
break
else:
B.append(1)
print len(B)
| 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 = 1e2 + 5;
int a[N];
multiset<int> st;
int main() {
ios_base ::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int n;
cin >> n;
for (int i = 1; i <= n; ++i) {
cin >> a[i];
}
sort(a + 1, a + n + 1);
int res = 0;
for (int i = 1; i <= n; ++i) {
auto it = st.begin();
if (it == st.end() || *it > a[i]) {
st.insert(1);
} else {
st.insert(*it + 1);
st.erase(it);
}
res = max(res, (int)st.size());
}
cout << res;
}
| 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())
arr=[int(x) for x in input().split()]
arr.sort()
ans=[]
for ele in arr:
for i in range(len(ans)):
if(ans[i]<=ele):
ans[i]+=1
break
else:
ans.append(1)
print(len(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 fa[105], cnt[105];
int findset(int x) {
if (fa[x] == x)
return x;
else
return fa[x] = findset(fa[x]);
}
void unionset(int x, int y) {
int fx = findset(x), fy = findset(y);
if (fx != fy) {
fa[fy] = fx;
cnt[fx] += cnt[fy];
}
}
int main() {
int n, x[105];
scanf("%d", &n);
for (int i = 1; i <= n; i++) scanf("%d", &x[i]);
sort(x + 1, x + n + 1);
for (int i = 0; i <= n; i++) fa[i] = i;
for (int i = 1; i <= n; i++) cnt[i] = 1;
for (int i = 1; i <= n; i++) {
int fi = findset(i), num = cnt[fi];
for (int j = i + 1; j <= n; j++) {
if (fa[j] != j) continue;
if (num > x[j]) continue;
unionset(i, j);
break;
}
}
int ans = 0;
for (int i = 1; i <= n; i++) {
if (findset(i) == i) ans++;
}
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 arr[101];
int main() {
int n;
cin >> n;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
sort(arr, arr + n);
int piles = 0, k = 0;
while (k < n) {
int j = 0;
for (int i = 0; i < n; i++) {
if (arr[i] >= j) {
j++;
arr[i] = -1;
k++;
}
}
piles++;
}
cout << piles << 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 | #include <bits/stdc++.h>
using namespace std;
int di[] = {0, 0, 1, -1, 1, 1, -1, -1};
int dj[] = {1, -1, 0, 0, 1, -1, 1, -1};
int arr[105];
int getNxt(int a) {
for (int i = a; i <= 100; i++)
if (arr[i]) return i;
return -1;
}
void form() {
int nxt = getNxt(0), len = 0;
while (nxt != -1) {
len++;
arr[nxt]--;
nxt = getNxt(max(nxt, len));
}
}
int main() {
ios_base::sync_with_stdio(false);
int n, a;
cin >> n;
for (int i = 0; i < n; i++) cin >> a, arr[a]++;
int ans = 0;
while (getNxt(0) != -1) {
ans++;
form();
}
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 | from math import ceil
n = int(input())
xs = list(map(int, input().split()))
ret = 1
xs.sort()
for i in range(n):
ret = max(ret, int(ceil((i+1)/(xs[i]+1))))
print(ret) | 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 collections import Counter
def check(arr):
l=len(arr)
for i in range(len(arr)):
if l-i-1>arr[i]:
return False
return True
def boredom(arr):
arr=sorted(arr,reverse=True)
for ans in range(1,len(arr)+1):
d={}
ind=0
for i in arr:
d[ind]=d.get(ind,[])+[i]
ind+=1
ind%=ans
flag=False
for i in d.keys():
if check(d[i])==False:
flag=True
break
if flag==False:
return ans
a=input()
lst=list(map(int,input().strip().split()))
print(boredom(lst)) | PYTHON3 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.