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.io.BufferedReader; import java.io.InputStreamReader; import java.util.ArrayList; import java.util.Arrays; import java.util.StringTokenizer; public class C { void solve() throws Exception { int n = nextInt(); int[] x = nextInts(n); ArrayList[] piles = new ArrayList[n]; for (int i=0; i<n; i++) piles[i] = new ArrayList<Integer>(); Arrays.sort(x); for (int i=0; i<n; i++) { for (ArrayList<Integer> pile : piles) { if (x[i] >= pile.size()) { pile.add(x[i]); break; } } } for (int i=0; i<n; i++) { if (piles[i].isEmpty()) { System.out.println(i); return; } } System.out.println(n); } BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in)); StringTokenizer st = new StringTokenizer(""); String nextLine() throws Exception { String line = stdin.readLine(); st = new StringTokenizer(""); return line; } int[] nextInts(int n) throws Exception { int[] res = new int[n]; for (int i=0; i<n; i++) res[i] = nextInt(); return res; } double[] nextDoubles(int n) throws Exception { double[] res = new double[n]; for (int i=0; i<n; i++) res[i] = nextDouble(); return res; } String next() throws Exception { while (!st.hasMoreTokens()) st = new StringTokenizer(stdin.readLine()); return st.nextToken(); } int nextInt() throws Exception { return Integer.parseInt(next()); } double nextDouble() throws Exception { return Double.parseDouble(next()); } public static void main(String[] args) throws Exception { new C().solve(); } }
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 = input() boxes = map(int, raw_input().split()) s = [0 for i in range(101)] e = [0 for i in range(102)] for b in boxes : s[b] += 1 e[1] = s[0] for i in range(1, 101) : if s[i] == 0 : pass else : for j in range(1, i+1) : # print '[%d %d] %d %d' % (i, j, s[i], e[j]) if e[j] * (i-j+1) <= s[i] : s[i] -= e[j] * (i-j+1) e[i+1] += e[j] e[j] = 0 else : # print 'else %d %d' % (s[i], (i-j+1)) cnt = s[i] / (i-j+1) e[j] -= cnt e[i+1] += cnt if s[i] % (i-j+1) != 0 : e[j] -= 1 e[j+s[i]%(i-j+1)] += 1 s[i] = 0 e[i+1] += s[i] / (i+1) e[s[i]%(i+1)] += 1 # print 's = %d num = %d' % (i, s[i]) # print zip(range(1,21), e[1:21]) # print e[1:] print sum(e[1:])
PYTHON
389_C. Fox and Box Accumulation
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≀ n ≀ 100). The next line contains n integers x1, x2, ..., xn (0 ≀ xi ≀ 100). Output Output a single integer β€” the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image>
2
9
#include <bits/stdc++.h> using namespace std; int n, i, j, T, a[200], top[200]; int main() { scanf("%d\n", &n); for (i = 1; i <= n; i++) scanf("%d", a + i); sort(a + 1, a + n + 1); top[T = 1] = 0; for (i = 2; i <= n; i++) { for (j = 1; j <= T; j++) if (top[j] < a[i]) { top[j]++; break; } if (j == T + 1) top[++T] = 0; } printf("%d\n", T); 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
a=int(input()) z=list(map(int,input().split())) from bisect import * z.sort() index=0 count=0 while(len(z)): r=bisect_left(z,index) if(r==len(z)): count+=1 index=0 else: index+=1 z.pop(r) print(count+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
#include <bits/stdc++.h> #pragma GCC optimize("O3") using namespace std; int n, v[102]; bool tk[102]; int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); cin >> n; for (int i = 1; i <= n; ++i) cin >> v[i]; sort(v + 1, v + n + 1); int sol = 0; for (int i = 1; i <= n; ++i) { int nr = 0; if (!tk[i]) { ++sol; tk[i] = 1; ++nr; for (int j = i + 1; j <= n; ++j) { if (tk[j]) continue; if (v[j] >= nr) ++nr, tk[j] = 1; } } } cout << sol; return 0; }
CPP
389_C. Fox and Box Accumulation
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≀ n ≀ 100). The next line contains n integers x1, x2, ..., xn (0 ≀ xi ≀ 100). Output Output a single integer β€” the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image>
2
9
import java.util.*; import java.io.*; public class fast{ static class Parser { final int BUFFER_SIZE = 1 << 16; DataInputStream din; byte[] buffer; int bufferPointer, bytesRead; public Parser(InputStream in) { din = new DataInputStream(in); buffer = new byte[BUFFER_SIZE]; bufferPointer = bytesRead = 0; } public int nextInt() throws Exception { int ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = c == '-'; if (neg) c = read(); do { ret = ret * 10 + c - '0'; c = read(); } while (c > ' '); if (neg) return -ret; return ret; } public long nextLong() throws Exception { long ret = 0; byte c = read(); while (c <= ' ') c = read(); boolean neg = c == '-'; if (neg) c = read(); do { ret = ret * 10 + c - '0'; c = read(); } while (c > ' '); if (neg) return -ret; return ret; } public String next() throws Exception { StringBuffer ret=new StringBuffer(); byte c = read(); while (c <= ' ') c = read(); do { ret = ret.append((char)c); c = read(); } while (c > ' '); return ret.toString(); } private void fillBuffer() throws Exception { bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE); if (bytesRead == -1) buffer[0] = -1; } private byte read() throws Exception { if (bufferPointer == bytesRead) fillBuffer(); return buffer[bufferPointer++]; } } public static void main (String[] args) throws Exception{ Parser s = new Parser(System.in); PrintWriter ww = new PrintWriter(System.out,true); int n=s.nextInt(); int arr[]=new int[n]; boolean temp[]=new boolean[n]; for(int i=0;i<n;i++) arr[i]=s.nextInt(); Arrays.sort(arr); Arrays.fill(temp,false); int ans=0; int cnt=0; int store=n; while(n>0){ cnt=0; for(int i=0;i<store;i++){ if(arr[i]>=cnt&&temp[i]==false){ temp[i]=true; n--; cnt++; } } ans++; } ww.println(ans); ww.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
N = int(raw_input()) X = [int(s) for s in raw_input().split()] X.sort() for res in range(1, N + 1): for (i, x) in enumerate(X): if i / res > x: break else: print res exit(0)
PYTHON
389_C. Fox and Box Accumulation
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≀ n ≀ 100). The next line contains n integers x1, x2, ..., xn (0 ≀ xi ≀ 100). Output Output a single integer β€” the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image>
2
9
#include <bits/stdc++.h> using namespace std; int piles = 1, heavy = 0, num; int a[110], n; void solve(int x) { if (num == 0) { return; } if (heavy <= a[x]) { a[x] = -1; heavy++; num--; solve(x + 1); } else if (x < n) { solve(x + 1); } else { for (int i = 1; i <= n; i++) { if (a[i] != -1) { a[i] = -1; num--; heavy = 1; piles++; break; } } solve(1); } } int main() { cin >> n; num = n; for (int i = 1; i <= n; i++) { cin >> a[i]; } for (int i = 2; i <= n; i++) { for (int j = 1; j <= i; j++) { if (a[i] < a[j]) { swap(a[i], a[j]); } } } solve(1); 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
n=int(raw_input()) N=map(int,raw_input().split()) N.sort() u=ans=0 while u<n: ans+=1 h=0 for i in range(n): if N[i]>=h: N[i]= -1 h+=1 u+=1 print ans
PYTHON
389_C. Fox and Box Accumulation
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≀ n ≀ 100). The next line contains n integers x1, x2, ..., xn (0 ≀ xi ≀ 100). Output Output a single integer β€” the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image>
2
9
import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.io.PrintWriter; import java.util.ArrayList; import java.util.Collections; import java.util.Scanner; public class Task388A { public static void main(String... args) throws NumberFormatException, IOException { Solution.main(System.in, System.out); } static class Solution { public static void main(InputStream is, OutputStream os) throws NumberFormatException, IOException { PrintWriter pw = new PrintWriter(os); Scanner sc = new Scanner(is); int n = sc.nextInt(); ArrayList<ArrayList<Integer>> retVal = new ArrayList<>(); ArrayList<Integer> boxes = new ArrayList<>(n); for (int i = 0; i < n; i++) { boxes.add(sc.nextInt()); } Collections.sort(boxes); for (int i = 0; i < n; i++) { boolean added = false; for (int j = 0; j < retVal.size(); j++) { if (retVal.get(j).size() <= boxes.get(i)) { retVal.get(j).add(boxes.get(i)); added = true; break; } } if (!added) { ArrayList<Integer> tmp = new ArrayList<>(); tmp.add(boxes.get(i)); retVal.add(tmp); } } pw.println(retVal.size()); pw.flush(); sc.close(); } } }
JAVA
389_C. Fox and Box Accumulation
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≀ n ≀ 100). The next line contains n integers x1, x2, ..., xn (0 ≀ xi ≀ 100). Output Output a single integer β€” the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image>
2
9
#include <bits/stdc++.h> using namespace std; int a[1010]; int main() { int n, i; cin >> n; for (i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); int ans = 0; int x; for (int i = 0; i < n; i++) { x = 1; if (a[i] >= 0) { ans++; for (int j = i + 1; j < n; j++) { if (a[j] >= x) { x++; 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
import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int n = sc.nextInt(); int[] boxList = new int[n]; int[] boxKeyList = new int[n]; int maxList = 0; for (int i = 0; i < n; i++) { boxList[i] = sc.nextInt(); boxKeyList[i] = -1; } Arrays.sort(boxList); for (int i = 0; i < n; i++) { for (int j = 0; j < n; j++) { if (boxKeyList[j]==-1) { boxKeyList[j]=1; if (j>maxList) { maxList = j; } break; } if (boxKeyList[j]<=boxList[i] && boxList[i]!=0) { boxKeyList[j]++; break; } } } System.out.println(maxList+1); } }
JAVA
389_C. Fox and Box Accumulation
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≀ n ≀ 100). The next line contains n integers x1, x2, ..., xn (0 ≀ xi ≀ 100). Output Output a single integer β€” the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image>
2
9
#include <bits/stdc++.h> using namespace std; int n; int x[100 + 5]; int main() { for (int i = 0; i < 105; ++i) { x[i] = 0; } cin >> n; int now; for (int i = 0; i < n; ++i) { cin >> now; x[now]++; } int ans = 0, cnt = 0, level; while (cnt < n) { level = 0; for (int i = 0; i <= 100; ++i) { while (x[i] != 0 && i >= level) { cnt++; x[i]--; level++; } } ans++; } cout << ans << endl; return 0; }
CPP
389_C. Fox and Box Accumulation
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≀ n ≀ 100). The next line contains n integers x1, x2, ..., xn (0 ≀ xi ≀ 100). Output Output a single integer β€” the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image>
2
9
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.PrintWriter; import java.util.Arrays; import java.util.PriorityQueue; import java.util.StringTokenizer; public class Abood2C { public static void main(String[] args) throws IOException { Scanner sc = new Scanner(System.in); PrintWriter out = new PrintWriter(System.out); int n = sc.nextInt(); Integer[] p = new Integer[n]; for (int i = 0; i < n; i++) p[i] = sc.nextInt(); Arrays.sort(p); PriorityQueue<Integer> pq = new PriorityQueue<>(); for (int i = 0; i < n; i++) { if(pq.isEmpty() || pq.peek() > p[i]) pq.add(1); else pq.add(pq.remove() + 1); } out.println(pq.size()); out.flush(); out.close(); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s){ br = new BufferedReader(new InputStreamReader(s));} public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException {return Integer.parseInt(next());} public long nextLong() throws IOException {return Long.parseLong(next());} public String nextLine() throws IOException {return br.readLine();} public double nextDouble() throws IOException { String x = next(); StringBuilder sb = new StringBuilder("0"); double res = 0, f = 1; boolean dec = false, neg = false; int start = 0; if(x.charAt(0) == '-') { neg = true; start++; } for(int i = start; i < x.length(); i++) if(x.charAt(i) == '.') { res = Long.parseLong(sb.toString()); sb = new StringBuilder("0"); dec = true; } else { sb.append(x.charAt(i)); if(dec) f *= 10; } res += Long.parseLong(sb.toString()) / f; return res * (neg?-1:1); } public boolean ready() throws IOException {return br.ready();} } }
JAVA
389_C. Fox and Box Accumulation
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≀ n ≀ 100). The next line contains n integers x1, x2, ..., xn (0 ≀ xi ≀ 100). Output Output a single integer β€” the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image>
2
9
#include <bits/stdc++.h> using namespace std; int main() { int n, i, p, q, s, j, m, x; int a[101] = {0}; int b[101] = {0}; cin >> n; m = 0; for (i = 1; i <= n; i++) { cin >> x; m = max(m, x); a[x]++; } s = 0; for (i = 1; i <= a[0]; i++) b[i] = 1; if (a[0] > s) s = a[0]; for (i = 1; i <= m; i++) { j = 1; while (a[i] > 0) { if (b[j] < i + 1) { b[j]++; a[i]--; } else j++; } if (j > s) s = j; } printf("%d\n", s); }
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,a,c = input(),sorted(map(int,raw_input().split())),[0]*110 for v in a: mx = 0 for i in range(1,v+1): if c[i]: mx = i; break c[mx] -= 1; c[mx+1] += 1 print sum(c[1:])
PYTHON
389_C. Fox and Box Accumulation
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≀ n ≀ 100). The next line contains n integers x1, x2, ..., xn (0 ≀ xi ≀ 100). Output Output a single integer β€” the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image>
2
9
n=int(input()) a=list(map(int,input().split())) a.sort() piles=0 for i in range(n): if piles*(a[i]+1)<=i: piles+=1 print(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
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.net.URISyntaxException; import java.util.Arrays; import java.util.StringTokenizer; public class Main { public static void main(String[] args)throws IOException, URISyntaxException { Reader.init(System.in); StringBuilder s=new StringBuilder(); int n = Reader.nextInt(), arr[] = new int[n], i; for(i = 0; i < n; i++) arr[i] = Reader.nextInt(); Arrays.sort(arr); int cnt = 0, res = 0, cur; while(cnt < n) { res++; cur = 0; for(i = 0; i < n; i++) if(arr[i] >= cur) { arr[i] = -1; cur++; cnt++; } } s.append(res).append('\n'); System.out.print(s); } } class Reader { static BufferedReader reader; static StringTokenizer tokenizer; /** call this method to initialize reader for InputStream */ static void init(InputStream input) throws UnsupportedEncodingException { reader = new BufferedReader( new InputStreamReader(input, "UTF-8") ); tokenizer = new StringTokenizer(""); } /** get next word */ static String next() throws IOException { while ( ! tokenizer.hasMoreTokens() ) { //TODO add check for eof if necessary tokenizer = new StringTokenizer( reader.readLine() ); } return tokenizer.nextToken(); } static String nextLine() throws IOException { return reader.readLine(); } static int nextInt() throws IOException { return Integer.parseInt( next() ); } static double nextDouble() throws IOException { return Double.parseDouble( next() ); } static long nextLong() throws IOException { return Long.parseLong( next() ); } }
JAVA
389_C. Fox and Box Accumulation
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≀ n ≀ 100). The next line contains n integers x1, x2, ..., xn (0 ≀ xi ≀ 100). Output Output a single integer β€” the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image>
2
9
#include <bits/stdc++.h> using namespace std; vector<long long> a(101); long long n; bool f(long long x) { vector<vector<long long> > mas(101); long long i, j; for (i = 0; i < n; i++) { long long num = i % x; mas[num].push_back(a[i]); } for (i = 0; i < x; i++) { for (j = 0; j < mas[i].size(); j++) if (mas[i][j] < (mas[i].size() - j - 1)) return false; } return true; } int main() { cin >> n; long long i; for (i = 0; i < n; i++) { cin >> a[i]; } sort(a.begin(), a.begin() + n); reverse(a.begin(), a.begin() + n); for (i = 1; i <= n; i++) if (f(i)) { cout << i; return 0; } return 0; }
CPP
389_C. Fox and Box Accumulation
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≀ n ≀ 100). The next line contains n integers x1, x2, ..., xn (0 ≀ xi ≀ 100). Output Output a single integer β€” the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image>
2
9
#include <bits/stdc++.h> using namespace std; int a[110]; int h[110]; int main() { int i, j, tail, k, n, m; memset(h, 0, sizeof(h)); scanf("%d", &n); for (i = 0; i < n; i++) scanf("%d", &a[i]); tail = 0; sort(a, a + n); for (i = 0; i < n; i++) { int flag = 0; for (j = 0; j < tail; j++) { if (h[j] <= a[i]) { h[j]++; flag = 1; break; } } if (!flag) { h[tail] = 1; tail++; } } printf("%d\n", tail); }
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 sys import stdin n=int(input()) a= list(map(int,stdin.readline().split())) a.sort() piles=0 i=0 while len(a)>0: piles+=1 boxes=1 i=0 del a[0] while i<len(a): if a[i]>=boxes: boxes+=1 del a[i] else: i+=1 print(piles)
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 INF = INT_MAX; int n; vector<int> v; bool comp(int a, int b) { return a > b; } bool check(int mid) { vector<int> f(mid); for (int i = 0; i < mid; i++) f[i] = v[i]; for (int i = mid; i < n; i++) { if (f[i % mid] > 0) f[i % mid] = min(f[i % mid] - 1, v[i]); else { bool changed = false; for (int j = 0; j < mid; j++) if (f[j] > 0) { f[j] = min(f[j] - 1, v[i]), changed = true; break; } if (!changed) return false; } } return true; } int main() { ios_base::sync_with_stdio(false); cin >> n; v.resize(n); for (int i = 0; i < n; i++) cin >> v[i]; sort(v.begin(), v.end(), comp); int l = 1, r = n; while (r > l) { int mid = (l + r) / 2; if (check(mid)) r = mid; else l = mid + 1; } cout << r << 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()) a = list(map(int, input().split())) d = [0] * 101 for i in a: d[i] += 1 p = 0 while True: allZeros = True k = 0 for i in range(101): if d[i] != 0: while i >= k and d[i] > 0: d[i] -= 1 k += 1 allZeros = False if allZeros: break else: p += 1 print(p)
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, x[100], height[100], ans = 0; cin >> n; for (int i = 0; i < n; i++) cin >> x[i]; sort(x, x + n); for (int i = 0; i < n; i++) { bool find = false; for (int j = 0; j < ans; j++) { if (height[j] <= x[i]) { find = true; height[j]++; break; } } if (!find) { ans++; height[ans - 1] = 1; } } cout << ans; return 0; }
CPP
389_C. Fox and Box Accumulation
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≀ n ≀ 100). The next line contains n integers x1, x2, ..., xn (0 ≀ xi ≀ 100). Output Output a single integer β€” the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image>
2
9
#include <bits/stdc++.h> using namespace std; long long int gcd(long long int a, long long int b) { if (!b) return a; return gcd(b, a % b); } long long int power(long long int x, long long int y, long long int p) { long long int res = 1; x %= p; while (y > 0) { if (y & 1) res = (res * x) % p; y = y >> 1; x = (x * x) % p; } return res; } long long int lcm(long long int a, long long int b) { return (a * b) / gcd(a, b); } long long int searchll(long long int val, vector<long long int> vec) { for (long long int i = 0; i < vec.size() - 1; i++) { if (vec[i] == val) { return i; } } return -1; } bool isPrime(long long int n) { int broken = 0; for (long long int i = 2; i < sqrt(n); i++) { if (n % i == 0) { broken = 1; break; } } if (broken == 1) { return false; } else { return true; } } bool isPerfectSquare(long double x) { long double sr = sqrt(x); return ((sr - floor(sr)) == 0); } vector<bool> SieveOfEratosthenes(long long int num) { vector<bool> pno; pno.assign(num + 1, true); pno[0] = false; pno[1] = false; for (long long int i = 2; i * i <= num; i++) { if (pno[i] == true) { for (long long int j = i * 2; j <= num; j += i) pno[j] = false; } } return pno; } void solve() { long long int n; cin >> n; vector<long long int> weights; for (long long int i = 0; i < n; i++) { long long int x; cin >> x; weights.push_back(x); } sort(weights.begin(), weights.end()); long long int stacks = 0; long long int remSize = 0; long long int start; int broken = 0; long long int used = 0; long long int ans = 0; while (used < n) { long long int h = 0; ans++; for (long long int i = 0; i < n; i++) { if (weights[i] >= h) { weights[i] = -1; used++; h++; } } } cout << ans << "\n"; } signed main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); 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 collections, bisect, heapq n = int(input()) arr = list(map(int, input().split())) arr.sort() t = [] for a in arr: if not t or a < t[0]: heapq.heappush(t, 1) else: c = heapq.heappop(t) heapq.heappush(t, c + 1) print(len(t))
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> #pragma comment(linker, "/STACK:200000000") using namespace std; const int MOD = 1000000007; int main() { int n; scanf("%d", &n); int a[105]; for (int(i) = 0; (i) < (n); (i)++) scanf("%d", &a[i]); sort(a, a + n); int b[104] = {0}; for (int(i) = 0; (i) < (n); (i)++) { for (int(j) = 0; (j) < (n); (j)++) if (a[i] >= b[j]) { b[j]++; break; } } for (int(i) = 0; (i) < (n + 1); (i)++) if (b[i] == 0) { printf("%d", i); break; } 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 math n = int(input()) arr = [int(z) for z in input().split()] arr.sort() r = 0 for i in range(n): e = arr[i] k = math.ceil((i+1) / (e+1)) r = max(r, k) 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
#include <bits/stdc++.h> using namespace std; int arr[105]; bool compare(int x, int y) { return x > y; } bool ok(int x, int n) { int y = 0; int rem[105] = {0}; int i; for (i = 0; i < n; ++i) { if (i > x - 1) { rem[y] = min(rem[y] - 1, arr[i]); if (rem[y] < 0) { return false; } y = (y + 1) % x; continue; } rem[y] = arr[i]; y = (y + 1) % x; } return true; } int ans(int n) { int s = 1; int e = n; int m; while (s < e) { m = s + (e - s) / 2; if (ok(m, n)) { e = m; } else s = m + 1; } return s; } int main() { int n; scanf("%d", &n); for (int i = 0; i <= (int)n - 1; i++) { scanf("%d", &arr[i]); } sort(arr, arr + n, compare); printf("%d\n", 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
def arr_inp(): return [int(x) for x in stdin.readline().split()] from sys import * from collections import deque from bisect import * n, a, ans, all = int(input()), sorted(arr_inp()), 0, [] for i in range(n): if not a[i]: ans += 1 insort_right(all, 1) else: ix = bisect_right(all, a[i]) if ix != len(all) and all[ix] == a[i]: all[ix] += 1 elif ix: all[ix - 1] += 1 else: insort_right(all, 1) ans += 1 print(ans)
PYTHON3
389_C. Fox and Box Accumulation
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≀ n ≀ 100). The next line contains n integers x1, x2, ..., xn (0 ≀ xi ≀ 100). Output Output a single integer β€” the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image>
2
9
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; import java.util.Arrays; import java.util.StringTokenizer; public class CopyOfC { public static void main(String[] args) { MyScanner in = new MyScanner(); int n = in.nextInt(); int[] x = new int[n]; int[] num = new int[101]; for (int i = 0; i < n; i++) { x[i] = in.nextInt(); num[x[i]]++; } int ans = 0; while (n > 0) { for (int cap = 0; cap <= 100; cap++) { for (int j = cap; j <= 100; j++) { if (num[j] > 0) { num[j]--; n--; break; } } } ans++; } System.out.println(ans); } public static class Pair implements Comparable<Pair> { int x, y; public Pair(int x, int y) { this.x = x; this.y = y; } @Override public int compareTo(Pair o) { return Integer.compare(this.x, o.x); } @Override public int hashCode() { return x ^ y; } @Override public boolean equals(Object o) { Pair p = (Pair) o; return p.x == x && p.y == y; } } // -----------MyScanner class for faster input---------- public static class MyScanner { BufferedReader br; StringTokenizer st; public MyScanner() { 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; } } // -------------------------------------------------------- }
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.*; import java.io.*; public class ultrafast { static class InputReader { private InputStream stream; private byte[] inbuf = new byte[1024]; private int start= 0; private int end = 0; public InputReader(InputStream stream) { this.stream = stream; } private int readByte() { if (start == -1) throw new UnknownError(); if (end >= start) { end= 0; try { start= stream.read(inbuf); } catch (IOException e) { throw new UnknownError(); } if (start<= 0) return -1; } return inbuf[end++]; } private boolean isSpaceChar(int c) { return !(c >= 33 && c <= 126); } private int skip() { int b; while ((b = readByte()) != -1 && isSpaceChar(b)) ; return b; } public String next() { int b = skip(); StringBuilder sb = new StringBuilder(); while (!(isSpaceChar(b))) { // when nextLine, (isSpaceChar(b) && b != ' ') sb.appendCodePoint(b); b = readByte(); } return sb.toString(); } public int nextInt() { int num = 0, b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } public long nextLong() { long num = 0; int b; boolean minus = false; while ((b = readByte()) != -1 && !((b >= '0' && b <= '9') || b == '-')) ; if (b == '-') { minus = true; b = readByte(); } while (true) { if (b >= '0' && b <= '9') { num = num * 10 + (b - '0'); } else { return minus ? -num : num; } b = readByte(); } } } public static void main(String args[]) { InputReader sc=new InputReader(System.in); int n=sc.nextInt(); int x[]=new int[n]; for(int i=0;i<n;i++) { x[i]=sc.nextInt(); } Arrays.sort(x); int b=0; for(int i=0;i<n;i++) { if((b*(x[i]+1))<=i) { b++; } } System.out.println(b); } }
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 dx[] = {-1, 0, 1, 0}; int dy[] = {0, 1, 0, -1}; int dx2[] = {1, -1, -1, 1, 0, 0, -1, 1}; int dy2[] = {1, -1, 1, -1, 1, -1, 0, 0}; int kmx[] = {-1, -1, 1, 1, 2, -2, 2, -2}; int kmy[] = {2, -2, 2, -2, -1, -1, 1, 1}; class Timer { public: clock_t T; Timer() { T = clock(); } ~Timer() { fprintf(stderr, "\n%.3f\n", double(clock() - T) / CLOCKS_PER_SEC); } }; int read() { int x; scanf("%d", &x); return x; } long long readL() { long long x; scanf("%lld", &x); return x; } const int N = 0; int main() { int n = read(); int a[105] = {}; for (int i = 0; i < n; i++) { a[i] = read(); } sort(a, a + n); int cnt = 0; int ans = 0; while (cnt < n) { int h = 0; ans++; for (int i = 0; i < n; i++) { if (a[i] >= h) { h++; a[i] = -1; cnt++; } } } 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
import java.io.IOException; import java.io.InputStream; import java.util.InputMismatchException; public class Main { public static void main(String[] args) { InputReader jin = new InputReader(System.in); int n = jin.readInt(); int[] a = new int[n]; int[] count = new int[101]; int[] piles = new int[101]; for ( int i = 0; i < 101; i++ ) { count[i] = 0; piles[i] = 0; } for ( int i = 0; i < n; i ++ ) { a[i] = jin.readInt(); count[a[i]] ++; } int max = 0; for ( int i = 0; i < 101; i++ ) { //for the ith value of strength for ( int j = 0; j < count[i]; j++ ) { //for the jth block for ( int k = 0; k < 101; k++ ) { //set a pile if ( piles[k] <= i ) { piles[k] ++; max = Math.max(k+1, max); break; } } } } System.out.println ( max ); } } class InputReader { private InputStream stream; private byte[] buf = new byte[102400]; // a byte buffer to store the // characters in private int curChar; // to hold the count of current character private int numChars; // number of characters public InputReader(InputStream stream) { // pass the inputstream class this.stream = stream; } public final int read() { if (numChars == -1) throw new InputMismatchException(); if (curChar >= numChars) { curChar = 0; try { numChars = stream.read(buf); // this is the implicit function // present in the inputStream // which reads a Character into // a temporary buffer } catch (IOException e) { throw new InputMismatchException(); } if (numChars <= 0) return -1; } return buf[curChar++]; } public final int readInt() { // a function to read nextInteger skipping the // newlines and empty spaces int c = read(); while (isSpaceChar(c)) // c = read(); int sgn = 1; if (c == '-') { // if the number is negative sgn = -1; c = read(); } int res = 0; // integer variable to hold the number do { if (c < '0' || c > '9') throw new InputMismatchException(); res *= 10; res += c - '0'; c = read(); } while (!isSpaceChar(c)); return res * sgn; } public final long readLong() { // similar as Integer 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 final String readString() { int c = read(); // read function returns one character at a time and the // unicode value of the character is returned while (isSpaceChar(c)) c = read(); StringBuilder res = new StringBuilder(); // using a String Builder to // build the String do { res.appendCodePoint(c); // appendCodePoint function to append the // character from its unicode value c = read(); } while (!isSpaceChar(c)); return res.toString(); } public final static boolean isSpaceChar(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public final String next() { return readString(); } }
JAVA
389_C. Fox and Box Accumulation
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≀ n ≀ 100). The next line contains n integers x1, x2, ..., xn (0 ≀ xi ≀ 100). Output Output a single integer β€” the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image>
2
9
#include <bits/stdc++.h> using namespace std; long long pow(long long x, long long y, long long mod) { long long temp; if (y == 0) return 1; temp = (pow(x, y / 2, mod)) % mod; if (y % 2 == 0) return (temp * temp) % mod; else return (((x * temp) % mod) * temp) % mod; } void solve(long long tno) { long long n; cin >> n; vector<long long> a(n); for (long long i = 0; i < n; i++) cin >> a[i]; sort(a.begin(), a.end()); long long b = 0; for (long long i = 0; i < n; i++) { if (b * (a[i] + 1) <= i) b++; } cout << b; } int32_t main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL); long long t; t = 1; for (long long i = 1; i <= t; i++) solve(i); }
CPP
389_C. Fox and Box Accumulation
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≀ n ≀ 100). The next line contains n integers x1, x2, ..., xn (0 ≀ xi ≀ 100). Output Output a single integer β€” the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image>
2
9
n = int(raw_input()) c = [ 0 for i in range(200) ] l = map(int , raw_input().split()) for i in l: c[i] += 1 ans = 0 RANGE = range(101); while True: flag = False for i in RANGE: if c[i]: flag = True cnt = 1 c[i] -= 1 ans += 1 for j in RANGE: while j >= cnt and c[j]: c[j] -= 1 cnt += 1 break if not flag: break print ans
PYTHON
389_C. Fox and Box Accumulation
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≀ n ≀ 100). The next line contains n integers x1, x2, ..., xn (0 ≀ xi ≀ 100). Output Output a single integer β€” the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image>
2
9
import sys n = int(sys.stdin.readline()[:-1]) a = [ int(i) for i in sys.stdin.readline().split()] a = sorted(a) M = [] for i in range(len(a)): if M == []: newar = [a[i]] M.append(newar) else: minsize = min(M, key = lambda x: len(x)) index = M.index(minsize) if len(minsize) <= a[i]: M[index].append(a[i]) else: M.append([a[i]]) # print M print len(M)
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.util.*; import java.io.*; public class A{ public static void main(String[] args) throws IOException { Scanner sc=new Scanner(System.in); PrintWriter pw=new PrintWriter(System.out); int n=sc.nextInt(); int ans=0; int []cnt=new int[110]; for(int j=0;j<n;j++) cnt[sc.nextInt()]++; int []piles=new int [n]; for(int i=0;i<110;i++) for(int p=0;p<n;p++) while(cnt[i]>0 && piles[p]<=i) { cnt[i]--; piles[p]++; } for(int p:piles) if(p>0) ans++; pw.println(ans); pw.close(); } static class Scanner { StringTokenizer st; BufferedReader br; public Scanner(InputStream s) { br = new BufferedReader(new InputStreamReader(s)); } public Scanner(FileReader s) { br = new BufferedReader(s); } public String next() throws IOException { while (st == null || !st.hasMoreTokens()) st = new StringTokenizer(br.readLine()); return st.nextToken(); } public int nextInt() throws IOException { return Integer.parseInt(next()); } public long nextLong() throws IOException { return Long.parseLong(next()); } public String nextLine() throws IOException { return br.readLine(); } public boolean ready() throws IOException {return br.ready();} public double nextDouble() throws IOException {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(raw_input()) arr=sorted([int(i) for i in raw_input().split()]) l=[] for x in arr: k=True for i in range(len(l)): if l[i]<=x: l[i]+=1 k=False break if k: l.append(1) print len(l)
PYTHON
389_C. Fox and Box Accumulation
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≀ n ≀ 100). The next line contains n integers x1, x2, ..., xn (0 ≀ xi ≀ 100). Output Output a single integer β€” the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image>
2
9
raw_input() A = sorted(map(int, raw_input().split())) ans = 0 while len(A) > 0: c = 0 for i in xrange(len(A)): if A[i] >= c: A[i] = -1 c += 1 A = filter(lambda x: x != -1, A) ans += 1 print ans
PYTHON
389_C. Fox and Box Accumulation
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≀ n ≀ 100). The next line contains n integers x1, x2, ..., xn (0 ≀ xi ≀ 100). Output Output a single integer β€” the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image>
2
9
import java.io.*; import java.util.*; import java.math.*; public class Main { /** * @param args */ public static void main(String[] args) { // TODO Auto-generated method stub InputStream inputstream = System.in; OutputStream outputstream = System.out; InputReader in = new InputReader(inputstream); OutputWriter out = new OutputWriter(outputstream); mysolver mysol = new mysolver(); mysol.solve(in, out); out.close(); } } class treenode { int bits[] = new int[11]; int lazy; } class mysolver { int count; int size; int A[]; treenode[] tn; int power[]; public void solve(InputReader in,OutputWriter out) { int n = in.readInt(); int A[] = new int[n]; for(int i=0;i<n;i++) { A[i] = in.readInt(); } Arrays.sort(A); int l=0; int m = n-1; while(l<m) { int temp= A[l]; A[l]=A[m]; A[m] = temp; l++; m--; } /*for(int i=0;i<n;i++) { System.out.println(A[i]); }*/ int size=0; for(size=1;size<=n;size++) { int check=0; for(int i=0;i<size;i++) { int val=0; for(int j=i;j<n;j+=size) { if(j==i) { val = A[j]; continue; } if(val==0) { check=1; } else { val = Math.min(val-1,A[j]); } } } if(check==0) break; } System.out.println(size); } } class InputReader { private InputStream stream; private byte[] buf = new byte[1024]; private int curChar; private int numChars; private InputReader.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 int readInt() { 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 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 isWhitespace(c); } public static boolean isWhitespace(int c) { return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1; } public String next() { return readString(); } public interface SpaceCharFilter { public boolean isSpaceChar(int ch); } } class OutputWriter { private final PrintWriter writer; public OutputWriter(OutputStream outputStream) { writer = new PrintWriter(new BufferedWriter(new OutputStreamWriter(outputStream))); } public OutputWriter(Writer writer) { this.writer = new PrintWriter(writer); } public void close() { writer.close(); } public void printLine(int i) { writer.println(i); } } class IOUtils { public static void readIntArrays(InputReader in, int[]... arrays) { for (int i = 0; i < arrays[0].length; i++) { for (int j = 0; j < arrays.length; j++) arrays[j][i] = in.readInt(); } } }
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.util.Arrays; public class CFTest104 { static BufferedReader br; public static void main(String[] args) { br = new BufferedReader(new InputStreamReader(System.in)); try { int n = readInt(); int[] arr = readIntArr(); br.close(); Arrays.sort(arr); int cnt = 0; boolean[] hv = new boolean[n]; for (int i = 0; i < n; i++) { if (!hv[i]) { cnt++; hv[i]=true; int cr = i; int nh=1; for (int j = i + 1; j < n; j++) { if (!hv[j]) { if (nh<=arr[j]) { hv[j] = true; nh++; cr = j; } } } } } // for(int i=0;i<n;i++){ // System.out.println(arr[i]); // } System.out.println(cnt); } catch (IOException e) { e.printStackTrace(); } } static String pro(int h1, int m1, int h2, int m2) { int nhr = h1 + h2; int nm = m1 + m2; if (nm > 59) { nm -= 60; nhr += 1; } String s = "" + nhr; if (nhr < 10) s = "0" + s; String s2 = "" + nm; if (nm < 10) s2 = "0" + s2; return s + ":" + s2; } static public String readLine() throws IOException { return br.readLine(); } static public String readString() throws IOException { return br.readLine(); } static public long readlong() throws IOException { return Long.parseLong(br.readLine()); } static public int readInt() throws IOException { return Integer.parseInt(br.readLine()); } static public int[] readIntArr() throws IOException { String[] str = br.readLine().split(" "); int arr[] = new int[str.length]; for (int i = 0; i < arr.length; i++) arr[i] = Integer.parseInt(str[i]); return arr; } static public double[] readDoubleArr() throws IOException { String[] str = br.readLine().split(" "); double arr[] = new double[str.length]; for (int i = 0; i < arr.length; i++) arr[i] = Double.parseDouble(str[i]); return arr; } static public long[] readLongArr() throws IOException { String[] str = br.readLine().split(" "); long arr[] = new long[str.length]; for (int i = 0; i < arr.length; i++) arr[i] = Long.parseLong(str[i]); return arr; } static public double readDouble() throws IOException { return Double.parseDouble(br.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
def solve(): for i in range(1, 101): pile = [0] * i ind = 0 for j in range(n): if pile[ind % i] <= L[j]: pile[ind % i] += 1 ind += 1 else: break else: return i n = input() L = sorted(map(int, raw_input().split())) print solve()
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 = 100; int x[N], n; bool good(int u) { for (int i = 0; i < n; i++) if (x[i] < i / u) return 0; return 1; } int main() { scanf("%d", &n); for (int i = 0; i < n; i++) scanf("%d", &x[i]); sort(x, x + n); int l = 1, r = n; while (l < r) { int mid = (l + r) / 2; if (good(mid)) r = mid; else l = mid + 1; } printf("%d", r); 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, x[101], f[101]; int comp(const void *a, const void *b) { return *(int *)a - *(int *)b; } int main() { ios::sync_with_stdio(false); cin >> n; x[0] = 0; for (int i = 1; i <= n; i++) cin >> x[i]; for (int i = 1; i <= n; i++) f[i] = 1; qsort(x, n + 1, sizeof(int), comp); int lf = n, ans = 0; while (lf) { int h = 0; ans++; for (int i = 1; i <= n; i++) if (x[i] >= h) { x[i] = -1; h++; lf--; } } cout << ans << endl; return 0; }
CPP
389_C. Fox and Box Accumulation
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≀ n ≀ 100). The next line contains n integers x1, x2, ..., xn (0 ≀ xi ≀ 100). Output Output a single integer β€” the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image>
2
9
import java.io.*; import java.util.*; public class Solution { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); String[] s = br.readLine().split("\\s"); int N = Integer.parseInt(s[0]); // int Q = Integer.parseInt(s[1]); s = br.readLine().split("\\s"); int[] arr = new int[N]; for(int i=0;i<N;++i) arr[i] = Integer.parseInt(s[i]); System.out.println(solve(N,arr)); } private static int solve(int N,int[] arr){ Arrays.sort(arr); List<List<Integer>> l = new ArrayList<List<Integer>>(); l.add(new ArrayList<Integer>()); l.get(0).add(arr[0]); for(int i=1;i<arr.length;++i){ int size = l.size(); boolean added = false; for(int j=0;j<size;++j){ if(l.get(j).size() <= arr[i]){ l.get(j).add(arr[i]); added = true; break; } } if(!added){ l.add(new ArrayList<Integer>()); l.get(l.size()-1).add(arr[i]); } } return l.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
n = int(input()) x = sorted(list(map(int, input().split()))) ans = 1 for i in range(n): if(x[i] < i//ans): ans += 1 print(ans)
PYTHON3
389_C. Fox and Box Accumulation
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≀ n ≀ 100). The next line contains n integers x1, x2, ..., xn (0 ≀ xi ≀ 100). Output Output a single integer β€” the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image>
2
9
import time,math,bisect,sys from sys import stdin,stdout from collections import deque from fractions import Fraction from collections import Counter from collections import OrderedDict pi=3.14159265358979323846264338327950 def II(): # to take integer input return int(stdin.readline()) def IO(): # to take string input return stdin.readline() def IP(): # to take tuple as input return map(int,stdin.readline().split()) def L(): # to take list as input return list(map(int,stdin.readline().split())) def P(x): # to print integer,list,string etc.. return stdout.write(str(x)) def PI(x,y): # to print tuple separatedly return stdout.write(str(x)+" "+str(y)+"\n") def lcm(a,b): # to calculate lcm return (a*b)//gcd(a,b) def gcd(a,b): # to calculate gcd if a==0: return b elif b==0: return a if a>b: return gcd(a%b,b) else: return gcd(a,b%a) def readTree(): # to read tree v=int(input()) adj=[set() for i in range(v+1)] for i in range(v-1): u1,u2=In() adj[u1].add(u2) adj[u2].add(u1) return adj,v def bfs(adj,v): # a schema of bfs visited=[False]*(v+1) q=deque() while q: pass def sieve(): li=[True]*1000001 li[0],li[1]=False,False for i in range(2,len(li),1): if li[i]==True: for j in range(i*i,len(li),i): li[j]=False prime=[] for i in range(1000001): if li[i]==True: prime.append(i) return prime def setBit(n): count=0 while n!=0: n=n&(n-1) count+=1 return count ##################################################################################### mx=10**9+7 def solve(): n=II() li=L() li.sort() tot=1 ans=0 while tot<=n: strength=0 for i in range(n): if li[i]>=strength: strength+=1 li[i]=-999 tot+=1 ans+=1 print(ans) solve() ####### # # ####### # # # #### # # # # # # # # # # # # # # # #### # # #### #### # # ###### # # #### # # # # #
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 INF = 2147483647; int inf = -2147483648; int dir[8][2] = {-1, 0, 1, 0, 0, -1, 0, 1, -1, -1, 1, 1, 1, -1, -1, 1}; const double PI = acos(-1.0); int a; int mapp[1005]; int main() { ios::sync_with_stdio(false); int n; int cnt = 0; int sum = 0; int sum1 = 0; cin >> n; for (int i = 0; i < n; i++) { cin >> a; mapp[a]++; } for (int i = 0; i <= 100; i++) { sum += mapp[i]; sum1 = ceil(sum * 1.0 / (i + 1)); inf = max(inf, sum1); } cout << inf << 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(raw_input().strip()) x = map(int, raw_input().strip().split()) x.sort() y = [] for item in x: put = False for i in xrange(len(y)): if y[i] <= item: y[i] += 1 put = True break if not put: y.append(1) print len(y)
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 int a[400]; long long int h[400]; multiset<long long int> st; int main() { ios_base ::sync_with_stdio(0); cin.tie(0); cout.tie(0); ; long long int n; cin >> n; long long int maxm = 0, l = -1, cnt = 0, lll = 5; for (int i = 0; i < n; i++) cin >> a[i], st.insert(a[i]), h[a[i]]++; sort(a, a + n); while (!st.empty()) { auto first = st.begin(); long long int p = *first; cnt++; h[p]--; st.erase(first); long long int num = 1; for (int i = 0; i < n; i++) { if (h[a[i]] && a[i] >= num) { num++; h[a[i]]--; st.erase(st.find(a[i])); } } } cout << cnt; }
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; cin >> n; int a[n]; for (int i = 0; i < n; i++) { cin >> a[i]; } sort(a, a + n); int count = 1; for (int i = 1; i < n; i++) { if (a[i] < (i / count)) count++; } cout << count; }
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; int ans; struct NODE { int w, s; } x[105]; int cmp(const NODE &a, const NODE &b) { if (a.s < b.s) return 1; else if (a.s == b.s) { if (a.w < b.w) return 1; else return 0; } else return 0; } int main() { int i, j, flag; scanf("%d", &n); for (i = 0; i < n; i++) { scanf("%d", &x[i].s); x[i].w = 1; } sort(x, x + n, cmp); ans = n; while (1) { for (i = 0, flag = 0; i < ans; i++) { for (j = i + 1; j < ans; j++) { if (x[i].w <= x[j].s) { x[j].s = min(x[i].s, x[j].s - x[i].w); x[j].w += x[i].w; x[i].s = 999999999, x[i].w = 999999999; flag = 1; ans--; break; } } if (flag) break; } if (!flag) break; else sort(x, x + ans + 1, cmp); } printf("%d\n", 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
#include <bits/stdc++.h> using namespace std; int a[120], b[120]; int main(void) { int n; scanf("%d", &n); for (int i = 0; i < n; ++i) scanf("%d", &a[i]); sort(a, a + n); int sum = 0; while (1) { int st = 0; while (st < n && b[st] != 0) ++st; if (st >= n) break; int d = 0; for (int i = st; i < n; ++i) { if (b[i] == 0 && a[i] >= d) { ++d; b[i] = 1; } } ++sum; } printf("%d\n", sum); }
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
# Target - Expert on CF # Be Humblefool import sys inf = float("inf") # sys.setrecursionlimit(10000000) # abc='abcdefghijklmnopqrstuvwxyz' # abd={'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25} # mod, MOD = 1000000007, 998244353 words = {1:'one',2:'two',3:'three',4:'four',5:'five',6:'six',7:'seven',8:'eight',9:'nine',10:'ten',11:'eleven',12:'twelve',13:'thirteen',14:'fourteen',15:'quarter',16:'sixteen',17:'seventeen',18:'eighteen',19:'nineteen',20:'twenty',21:'twenty one',22:'twenty two',23:'twenty three',24:'twenty four',25:'twenty five',26:'twenty six',27:'twenty seven',28:'twenty eight',29:'twenty nine',30:'half'} # vow=['a','e','i','o','u'] # dx,dy=[-1,1,0,0],[0,0,1,-1] # import random # from collections import deque, Counter, OrderedDict,defaultdict # from heapq import nsmallest, nlargest, heapify,heappop ,heappush, heapreplace # from math import ceil,floor,log,sqrt,factorial,pi,gcd # from bisect import bisect,bisect_left,bisect_right,insort,insort_left,insort_right def get_array(): return list(map(int, sys.stdin.readline().strip().split())) def get_ints(): return map(int, sys.stdin.readline().strip().split()) def input(): return sys.stdin.readline().strip() n = int(input()) Arr = get_array() Arr.sort() h = [0] for x in Arr: if x<min(h): h+=[1] else: h[h.index(min(h))]+=1 print(len(h))
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.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.io.OutputStream; import java.util.Arrays; import java.io.InputStreamReader; import java.io.FileNotFoundException; import java.io.File; import java.util.StringTokenizer; import java.io.Writer; import java.io.BufferedReader; import java.io.UnsupportedEncodingException; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top * * @author MaxHeap */ public class Main { public static void main(String[] args) { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastReader in = new FastReader(inputStream); OutputWriter out = new OutputWriter(outputStream); FoxAndAccumulation solver = new FoxAndAccumulation(); solver.solve(1, in, out); out.close(); } static class FoxAndAccumulation { public void solve(int testNumber, FastReader in, OutputWriter out) { int n = in.nextInt(); int[] arr = in.nextIntArray(n); boolean[] used = new boolean[n]; int ans = 0; Arrays.sort(arr); for (int x = 0; x < n; x++) { if (!used[x]) { ans += 1; used[x] = true; int curr = 1; for (int i = x + 1; i < n; i++) { if (!used[i]) { if (arr[i] >= curr) { used[i] = true; curr++; } } } } } out.println(ans); } } static class OutputWriter extends PrintWriter { public OutputWriter(OutputStream os, boolean autoFlush) { super(os, autoFlush); } public OutputWriter(Writer out) { super(out); } public OutputWriter(Writer out, boolean autoFlush) { super(out, autoFlush); } public OutputWriter(String fileName) throws FileNotFoundException { super(fileName); } public OutputWriter(String fileName, String csn) throws FileNotFoundException, UnsupportedEncodingException { super(fileName, csn); } public OutputWriter(File file) throws FileNotFoundException { super(file); } public OutputWriter(File file, String csn) throws FileNotFoundException, UnsupportedEncodingException { super(file, csn); } public OutputWriter(OutputStream out) { super(out); } public void flush() { super.flush(); } public void close() { super.close(); } } static class FastReader { BufferedReader reader; StringTokenizer st; public FastReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); 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 int[] nextIntArray(int n) { int[] arr = new int[n]; int i = 0; while (i < n) { arr[i++] = nextInt(); } return arr; } } }
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; bool Can(vector<int> v, int x) { for (int i = 0; i < ((int)(v).size()); i++) if (v[i] < i / x) return false; return true; } int main() { int n; scanf("%d", &n); vector<int> v(n); for (int i = 0; i < n; i++) scanf("%d", v.begin() + i); sort(v.begin(), v.end()); int Upper = n; int Lower = 1; while (Lower != Upper) { int Mid = (Upper + Lower) / 2; if (Can(v, Mid)) Upper = Mid; else Lower = Mid + 1; } printf("%d\n", Lower); }
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()) l=list(map(int,input().split())) l=sorted(l) l=l[::-1] l1=[0]*n k=0 for i in range(n) : if l1[i]!=1 : t=l[i] p=1 r=0 l1[i]==1 V=[t] for j in range(n) : if l1[j]==0 and l[j]<t : t=l[j] l1[j]=1 V.append(t) r=r+1 for j in range(n-1,-1,-1) : if l1[j]!=1 : if l[j] in V : q=V.index(l[j])+1 if len(V)-q+1<=l[j] : c=0 s=-1 u=len(V)-q+1 for e in range(q-1,-1,-1) : if V[e]>=u+s : s=s+1 else : c=1 break if c==0 : l1[j]=1 V=V[:q-1]+[l[j]]+V[q-1:] k=k+1 print(k)
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 N = 105; int n, a[N]; bool vis[N]; int main(void) { scanf("%d", &n); for (int i = 0; i < n; i++) { scanf("%d", &a[i]); } sort(a, a + n); int ans = 0; bool flag = true; while (flag) { ans++; int now = 0; for (int i = 0; i < n; i++) { if (vis[i]) { continue; } if (a[i] >= now) { now++; vis[i] = true; } else { continue; } } int t = 0; for (int i = 0; i < n; i++) { if (!vis[i]) { t++; } } if (t == 0) { flag = false; } } 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
n = int(raw_input()) a = map(int, raw_input().split()) a.sort() 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
def check(mid , lis): pile=[10000000000]*mid c=0 for i in range(n-1,-1,-1): pile[i%mid]=min(pile[i%mid]-1,lis[i]) # print(pile,mid) if min(pile)<0: return 0 else: return 1 n = int(input()) lis = sorted(map(int,input().split())) l=1 r=n while l<=r: mid = l + (r-l)//2 # print(l,r,mid) if(check(mid,lis)): r = mid-1 else: l = mid+1 print(l)
PYTHON3
389_C. Fox and Box Accumulation
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≀ n ≀ 100). The next line contains n integers x1, x2, ..., xn (0 ≀ xi ≀ 100). Output Output a single integer β€” the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image>
2
9
n=int(raw_input()) a=map(int,raw_input().split()) a.sort() for ans in range(1,n+1): OK=1 b=[1 for i in range(ans)] j=0 for i in range(ans,n): if a[i]<b[j]: OK=0 break b[j]+=1 j+=1 if j==ans: j=0 if OK: print ans break
PYTHON
389_C. Fox and Box Accumulation
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≀ n ≀ 100). The next line contains n integers x1, x2, ..., xn (0 ≀ xi ≀ 100). Output Output a single integer β€” the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image>
2
9
import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.PrintWriter; import java.lang.reflect.Array; import java.text.SimpleDateFormat; import java.util.Arrays; import java.util.Locale; import java.util.Map; import java.util.StringTokenizer; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Algorithm { public static void main(String args[]) throws Exception { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); Solution s = new Solution(); s.solve(in, out); out.close(); } } class Solution { public void solve(InputReader in, PrintWriter out) { int n = in.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) { a[i] = in.nextInt(); } Arrays.sort(a); int sum = 0; int b; int count = 0; for (int i = 0; i < n; i++) { if (a[i] == -1) { continue; } b = a[i]; count = 1; a[i] = -1; for (int j = i + 1; j < n; j++) { if (a[j] >= b && a[j]>=count && a[j] > 0) { b = a[j]; count++; a[j] = -1; } } sum++; } out.print(sum); } public boolean sravni(String s1, String s2) { if (s2.length() > s1.length()) return false; int l = s1.length(); for (int i = 0; i < l; i++) { if (s1.charAt(i) < s2.charAt(i)) return false; } return true; } public void sortPair(Pair[] p) { int count = p.length; Pair t; for (int i = 0; i < count - 1; i++) { for (int j = i + 1; j < count; j++) { if (p[i].a > p[j].a) { t = p[i]; p[i] = p[j]; p[j] = t; } } } } class Pair { int i; int a; int p; public Pair(int i, int a) { this.i = i; this.a = a; } } } class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream)); tokenizer = null; } public String next() { while (tokenizer == null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } }
JAVA
389_C. Fox and Box Accumulation
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≀ n ≀ 100). The next line contains n integers x1, x2, ..., xn (0 ≀ xi ≀ 100). Output Output a single integer β€” the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image>
2
9
def check_append(list, elem): if elem >= len(list): # list.append(elem) return True else: return False n = int(input()) a = [int(x) for x in raw_input().split()] a.sort() main = [] for x in a: if len(main) == 0: main.append([x]) else: flag = True for t in range(len(main)): if check_append(main[t], x): main[t].append(x) flag = False break else: # main.append([x]) continue if flag: main.append([x]) print len(main)
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; vector<int> pile[102], v; int main() { ios_base::sync_with_stdio(false); int n, x; cin >> n; for (int i = 0; i < n; i++) cin >> x, v.push_back(x), pile[i].clear(); sort(v.begin(), v.end()); int ans = 0, box = 0; for (int i = 0; i < n; i++) { x = v[i]; for (int j = 0; j < 102; j++) { if (pile[j].size() <= x) { pile[j].push_back(x); break; } } } for (int i = 0; i <= n; i++) if (pile[i].size() == 0) { cout << i << endl; break; } 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()) boxes = [int(item) for item in input().split(' ')] boxes.sort() stacks = 0 while len(boxes): stacks += 1 n_boxes = [] current_weight = 0 for box in boxes: if box >= current_weight: current_weight += 1 else: n_boxes.append(box) boxes = n_boxes print(stacks)
PYTHON3
389_C. Fox and Box Accumulation
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≀ n ≀ 100). The next line contains n integers x1, x2, ..., xn (0 ≀ xi ≀ 100). Output Output a single integer β€” the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image>
2
9
n=int(input()) l=sorted(map(int,input().split())) pile,box=0,n visited=[0]*n while box!=0: t=0 for i in range(n): if l[i]>=t and visited[i]==0: visited[i]=1 t+=1 box-=1 if t>0: pile+=1 print(pile)
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
# Description of the problem can be found at http://codeforces.com/problemset/problem/388/A n = int(input()) l_b = list(map(int, input().split())) l_b.sort() p = 0 s_d = list() while len(l_b) > 0: t = 0 for i, b in enumerate(l_b): if b >= t: s_d.append(i) t += 1 for i in s_d[::-1]: del l_b[i] s_d = list() p += 1 print(p)
PYTHON3
389_C. Fox and Box Accumulation
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≀ n ≀ 100). The next line contains n integers x1, x2, ..., xn (0 ≀ xi ≀ 100). Output Output a single integer β€” the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image>
2
9
n = int(raw_input()) a = map(int, raw_input().split()) a.sort() count = [0] * 200 for elem in a: i = 0 while count[i] > elem: i += 1 count[i] += 1 answer = 0 i = 0 while count[i] > 0: i += 1 print i
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.util.*; import java.io.*; public class Main388A { static PrintWriter out=new PrintWriter(System.out); public static void main(String[] args) throws IOException { Scanner sc=new Scanner(System.in); int n=sc.nextInt(); int[] a=sc.nextIntArray(n); Arrays.sort(a); int cnt=0; int prev=a[n-1]; int used=0; int ans=0; while(used<n) { ans+=1; int f=0; for(int i=0;i<n;i++) { if(a[i]>=f) { a[i]=-1; used++; f++; } } } out.println(ans); out.flush(); } static class Scanner { BufferedReader br; StringTokenizer tk=new StringTokenizer(""); public Scanner(InputStream is) { br=new BufferedReader(new InputStreamReader(is)); } public int nextInt() throws IOException { if(tk.hasMoreTokens()) return Integer.parseInt(tk.nextToken()); tk=new StringTokenizer(br.readLine()); return nextInt(); } public long nextLong() throws IOException { if(tk.hasMoreTokens()) return Long.parseLong(tk.nextToken()); tk=new StringTokenizer(br.readLine()); return nextLong(); } public String next() throws IOException { if(tk.hasMoreTokens()) return (tk.nextToken()); tk=new StringTokenizer(br.readLine()); return next(); } public String nextLine() throws IOException { tk=new StringTokenizer(""); return br.readLine(); } public double nextDouble() throws IOException { if(tk.hasMoreTokens()) return Double.parseDouble(tk.nextToken()); tk=new StringTokenizer(br.readLine()); return nextDouble(); } public char nextChar() throws IOException { if(tk.hasMoreTokens()) return (tk.nextToken().charAt(0)); tk=new StringTokenizer(br.readLine()); return nextChar(); } 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[] nextIntArrayOneBased(int n) throws IOException { int a[]=new int[n+1]; for(int i=1;i<=n;i++) a[i]=nextInt(); return a; } public long[] nextLongArrayOneBased(int n) throws IOException { long a[]=new long[n+1]; for(int i=1;i<=n;i++) a[i]=nextLong(); return 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
__author__ = 'Shailesh' n = int(raw_input()) data = sorted(map(int, raw_input().split())) height = 1 piles = 1 i = 1 while i < len(data): if data[i] < height: piles += 1 i += height continue i += piles height += 1 print 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
n = int(input()) l = [int(i) for i in input().split()] l.sort() ans = 1 for i in range(n): if l[i] < i//ans: ans+=1 print(ans)
PYTHON3
389_C. Fox and Box Accumulation
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≀ n ≀ 100). The next line contains n integers x1, x2, ..., xn (0 ≀ xi ≀ 100). Output Output a single integer β€” the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image>
2
9
input();print-~max(x/-~f for x,f in enumerate(sorted(map(int,raw_input().split()))))
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 inf = 0x7FFFFFFF; struct point_int { int x, y; point_int() {} point_int(int a, int b) { x = a, y = b; } }; struct point_double { double x, y; point_double() {} point_double(double a, double b) { x = a, y = b; } }; struct Node { int v, w; Node() {} bool operator<(const Node &a) const { return w > a.w; } Node(int _v, int _w) { v = _v, w = _w; } }; template <class T> T gcd(T a, T b) { return b == 0 ? a : gcd(b, a % b); } template <typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; } template <class T> T big_mod(T n, T p, T m) { if (p == 0) return (T)1; T x = big_mod(n, p / 2, m); x = (x * x) % m; if (p & 1) x = (x * n) % m; return x; } template <class T> T multiplication(T n, T p, T m) { if (p == 0) return (T)0; T x = multiplication(n, p / 2, m); x = (x + x) % m; if (p & 1) x = (x + n) % m; return x; } template <class T> T my_pow(T n, T p) { if (p == 0) return 1; T x = my_pow(n, p / 2); x = (x * x); if (p & 1) x = (x * n); return x; } template <class T> double getdist(T a, T b) { return sqrt((a.x - b.x) * (a.x - b.x) + (a.y - b.y) * (a.y - b.y)); } template <class T> T extract(string s, T ret) { stringstream ss(s); ss >> ret; return ret; } template <class T> string tostring(T n) { stringstream ss; ss << n; return ss.str(); } template <class T> inline T Mod(T n, T m) { return (n % m + m) % m; } template <class T> T MIN3(T a, T b, T c) { return min(a, min(b, c)); } template <class T> T MAX3(T a, T b, T c) { return max(a, max(b, c)); } template <class T> void print_vector(T &v) { int sz = v.size(); if (sz) cout << v[0]; for (int i = 1; i < sz; i++) cout << ' ' << v[i]; cout << endl; } bool isVowel(char ch) { ch = toupper(ch); if (ch == 'A' || ch == 'U' || ch == 'I' || ch == 'O' || ch == 'E') return true; return false; } bool isConsonant(char ch) { if (isalpha(ch) && !isVowel(ch)) return true; return false; } int read_int() { int n; scanf("%d", &n); return n; } int read_LLD() { long long int n; scanf("%lld", &n); return n; } inline int buffer_input() { char inp[1000]; scanf("%s", inp); return atoi(inp); } bool visit[105]; vector<int> box; int main() { int n = buffer_input(); for (int i = 0; i < n; i++) { int x = buffer_input(); box.push_back(x); } sort(box.begin(), box.end()); int total = 0; for (int i = 0; i < n; i++) { if (visit[i] == false) { total++; int c = 1; for (int j = i + 1; j < n; j++) { if (box[j] >= c && visit[j] == false) { c++; visit[j] = true; } } } } cout << total << endl; return 0; }
CPP
389_C. Fox and Box Accumulation
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≀ n ≀ 100). The next line contains n integers x1, x2, ..., xn (0 ≀ xi ≀ 100). Output Output a single integer β€” the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image>
2
9
import java.io.*; import java.util.*; public class CodeforcesRound228Div2ProblemC { static class Problem { Scanner reader; PrintWriter writer; Problem() { reader = new Scanner(System.in); writer = new PrintWriter(System.out); } Problem(File inputFile, File outputFile) throws IOException { reader = new Scanner(inputFile); writer = new PrintWriter(outputFile); } void Run() { Solution(); reader.close(); writer.close(); } void Solution() { int n = reader.nextInt(), prev = n - 1, res = 1, x[] = new int[n]; for (int i = 0; i < n; i++) x[i] = reader.nextInt(); Arrays.sort(x); for (int i = 1; i <= n; i++) { boolean canBuild = true; for (int j = n - 1 - i; j >= 0; j--) for (int k = i; j + k < n; k += i) if (k / i > x[j + k]) canBuild = false; if (canBuild) { writer.println(i); return; } } } } public static void main(String args[]) throws IOException { Problem C = new Problem(); //Problem C = new Problem(new File ("input.txt"), new File("output.txt")); C.Run(); } }
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, ans = 0, c = 0; int a[123]; cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); for (int i = 0; i < n; i++) { if (a[i] != -1) { a[i] = -1; c++; for (int j = i + 1; j < n; j++) { if (a[j] >= c) { c++; a[j] = -1; } else if (a[j] > c) { j = i; c++; } } ans++; } c = 0; } cout << ans; return 0; }
CPP
389_C. Fox and Box Accumulation
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≀ n ≀ 100). The next line contains n integers x1, x2, ..., xn (0 ≀ xi ≀ 100). Output Output a single integer β€” the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image>
2
9
n = int(input()) a = 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; #pragma comment(linker, "/STACK:16777216") const double EPS = 1e-7; double iabs(const double a) { return (a < -EPS) ? -a : a; } double imin(const double a, const double b) { return (a - b > EPS) ? b : a; } double imax(const double a, const double b) { return (a - b > EPS) ? a : b; } template <class I> I iabs(const I a) { return (a < 0) ? -a : a; } template <class I> I imin(const I a, const I b) { return (a < b) ? a : b; } template <class I> I imax(const I a, const I b) { return (a < b) ? b : a; } template <class I> inline I mod_pow(const I& x, const long long p, const I& m) { if (p == 0) return 1; I mult = (p & 1) ? x : 1; I t = mod_pow(x, p / 2, m) % m; return (((mult * t) % m) * t) % m; } template <class T> inline T ipow(const T& x, const long long p) { if (p == 0) return 1; T mult = (p & 1) ? x : 1; T h = ipow(x, p / 2); return h * h * mult; } unsigned long long gcd(unsigned long long a, unsigned long long b) { if (a == 0) return b; return gcd(b % a, a); } template <class T> T next_power_of_two(T v) { if (v < 0) return 0; v--; v |= v >> 1; v |= v >> 2; v |= v >> 4; v |= v >> 8; v |= v >> 16; v |= v >> 32; v++; return v; } string bin(unsigned int i) { string res = ""; while (i != 0) { res += ('0' + (i % 2)); i = i / 2; } return string(res.rbegin(), res.rend()); } template <int SIZE> class DSU { public: int parent[SIZE]; int rank[SIZE]; int count; void clear() { for (int i = 0; i < SIZE; i++) { this->parent[i] = -1; this->rank[i] = 0; } this->count = 0; } DSU() { this->clear(); } void make(int x) { this->parent[x] = x; this->rank[x] = 1; this->count++; } bool in_a_set(int x) { return this->parent[x] != -1; } int find(int x) { if (x == this->parent[x]) return x; return this->parent[x] = find(this->parent[x]); } void combine(int x, int y) { x = this->find(x); y = this->find(y); if (x != y) { if (this->rank[x] > this->rank[y]) this->parent[x] = y; else this->parent[y] = x; this->count--; } } }; class BigInt { public: const static unsigned int N = 1000; const static unsigned int base = 10; unsigned int len; short sign; unsigned int digits[N]; BigInt(const BigInt& bi) { this->len = bi.len; this->sign = bi.sign; for (unsigned int i = 0; i < this->len; ++i) (*this)[i] = bi[i]; } BigInt(long long n) { this->len = 0; this->sign = (n >= 0) ? 1 : -1; this->digits[0] = 0; while (n) { this->digits[this->len] = n % this->base; n /= this->base; this->len++; } if (this->len == 0) this->len = 1; } BigInt(string s) { this->sign = (s[0] == '-') ? 1 : -1; this->digits[0] = 0; if (s[0] == '-') s = s.substr(1, s.length() - 1); this->len = s.length(); for (unsigned int i = 0; i < this->len; i++) (*this)[i] = s[this->len - i - 1] - '0'; } string toString() const { stringstream ss; for (int i = this->len - 1; i >= 0; --i) ss << (*this)[i]; return ss.str(); } unsigned int& operator[](const unsigned int i) { return digits[i]; } unsigned int operator[](const unsigned int i) const { if (i < this->len) return this->digits[i]; return 0; } bool iszero() const { if (this->len <= 1 && this->digits[0] == 0) return true; return false; } BigInt& operator=(const BigInt& rval) { if (this != &rval) { this->len = rval.len; this->sign = rval.sign; for (unsigned int i = 0; i < this->len; ++i) (*this)[i] = rval[i]; } return *this; } BigInt operator+(const BigInt& rhs) const { BigInt s(0); unsigned long long r = 0, d, i; for (i = 0; i < max(this->len, rhs.len); i++) { d = (*this)[i] + rhs[i] + r; r = d / this->base; s[i] = d % this->base; } s.len = max(this->len, rhs.len); if (r) s[s.len++] = r; return s; } BigInt operator+(unsigned long long rhs) const { BigInt s(*this); unsigned long long r = 0, d, i = 0; while (rhs != 0 || r != 0) { d = s[i] + (rhs % s.base) + r; rhs /= s.base; r = d / s.base; s[i] = d % s.base; i++; } if (i > s.len) s.len = i; return s; } BigInt operator*(unsigned long long rhs) const { if (rhs == 0) return BigInt(0); BigInt s(*this); unsigned long long r = 0, d, i; for (i = 0; i < s.len; ++i) { d = s[i] * rhs + r; r = d / this->base; s[i] = d % this->base; } while (r) s[s.len++] = r % this->base, r /= this->base; return s; } BigInt operator*(const BigInt& rhs) const { BigInt s(0); if (rhs.iszero()) return s; unsigned long long r, d, i, j, k; for (i = 0; i < this->N; i++) s[i] = 0; for (i = 0; i < this->len; i++) { r = 0; for (j = 0, k = i; j < rhs.len; j++, k++) { d = (*this)[i] * rhs[j] + r + s[k]; r = d / this->base; s[k] = d % this->base; } while (r) s[k++] = r % this->base, r /= this->base; if (k > s.len) s.len = k; } while (s.len > 1 && s[s.len - 1] == 0) s.len--; return s; } unsigned int operator%(unsigned int rhs) { BigInt t(*this); unsigned long long pow = 1; unsigned long long mod = 0; for (unsigned int i = 0; i < this->len && pow != 0; i++) { mod = (((*this)[i] % rhs) * pow + mod) % rhs; pow = (pow * this->base) % rhs; } return mod; } }; vector<long long> genprimes(const int n) { vector<long long> res; res.push_back(2); long long m, t, j; for (int i = 3; i <= n; i += 2) { j = 0; m = res.size(); t = (long long)sqrt(i * 1.0) + 1; while (j < m && res[j] < t && i % res[j] != 0) j++; if (j == m || res[j] >= t) res.push_back(i); } return res; } long long reverse_intereger(long long a) { int res = 0; while (a != 0) res = 10 * res + (a % 10), a /= 10; return res; } int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a); } int main() { int n, a, j, t, subs; vector<int> st[101], inp; cin >> n; for (int i = 0; i < n; ++i) { cin >> a; inp.push_back(a); st[i] = vector<int>(); } sort(inp.begin(), inp.end()); for (int i = 0; i < n; ++i) { a = inp[i]; j = 0; t = -1; subs = -1; for (; j < n; ++j) { if (st[j].size() <= a) { if (t == -1 || (t > 0 && a - st[j].size() < subs)) { t = j; subs = a - st[j].size(); } } } st[t].push_back(a); } a = 0; for (int i = 0; i < n; ++i) { if (st[i].size() > 0) { a++; } } cout << a; 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> const int INF = 0x7F7F7F7F; const double EPS = 1e-10; const long long mod7 = 1e9 + 7; const long long mod9 = 1e9 + 9; using namespace std; inline long long rit() { long long f = 0, key = 1; char c; do { c = getchar(); if (c == '-') key = -1; } while (c < '0' || c > '9'); do { f = f * 10 + c - '0'; c = getchar(); } while (c >= '0' && c <= '9'); return f * key; } inline void fprt(double f) { printf("%.08lf", f); } void init() {} const int Z = 105; int n; int a[Z], mk[Z]; void read() { n = rit(); for (int i = 0; i < n; ++i) a[i] = rit(); sort(a, a + n); } void solve() { int cnt = 0, c2 = 0, now; while (8 * 7 != 87) { cnt++; now = 0; for (int i = 0; i < n; ++i) { if (mk[i]) continue; if (a[i] >= now) { mk[i] = 1; c2++; now++; if (c2 == n) break; } } if (c2 == n) break; } cout << cnt << endl; } int main() { int nn = 1; while (nn--) { init(), read(), 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.*; public class C389C { public static void main(String[] args) { Scanner ah = new Scanner(System.in); int n = ah.nextInt() , i , j , k , s = 0, a [] = new int[n]; for(i = 0;i < n;i ++)a[i] = ah.nextInt(); Arrays.sort(a); boolean b[] = new boolean[n]; for(i = 0;i < n;i ++) if(!b[i]){ k = 1; for(j = i + 1;j < n;j ++) if(!b[j] && a[j] >= k){ k ++; b[j] = true; } s ++; } System.out.println(s); } }
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 BoxAccumulation { public static void main(String[] args) { // TODO Auto-generated method stub Scanner in = new Scanner(System.in); int n = in.nextInt(); int[] a = new int[n]; for (int i = 0; i < n; i++) a[i] = in.nextInt(); boolean[] was = new boolean[n]; Arrays.fill(was, false); Arrays.sort(a); int res = 0; while (true) { int i = 0; for (i = 0; i < n; i++) if (!was[i]) { //start a new stack res++; int[] s = new int[n]; int index = 0; s[0] = a[i]; was[i] = true; //try to add more for (int j = i + 1; j < n; j++) if (!was[j] && a[j] > index) { s[index++] = a[j]; was[j] = true; } } if (i == n) break; } 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 java.util.*; import java.io.*; import java.lang.*; import java.math.*; public class C { public static void main(String[] args) throws Exception { BufferedReader bf = new BufferedReader(new InputStreamReader(System.in)); // Scanner scan = new Scanner(System.in); // PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out)); int n = Integer.parseInt(bf.readLine()); StringTokenizer st = new StringTokenizer(bf.readLine()); int[] a = new int[n]; int[] counters = new int[101]; for(int i=0; i<n; i++) { a[i] = Integer.parseInt(st.nextToken()); for(int j=a[i]; j<=100; j++) counters[j]++; } int max = -1; // System.out.println(Arrays.toString(counters)); for(int i=0; i<101; i++) { int x = counters[i]/(i+1); if(counters[i] % (i+1) != 0) x++; if(x > max) max = x; } System.out.println(max); // int n = Integer.parseInt(st.nextToken()); // int n = scan.nextInt(); // out.close(); System.exit(0); } }
JAVA
389_C. Fox and Box Accumulation
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≀ n ≀ 100). The next line contains n integers x1, x2, ..., xn (0 ≀ xi ≀ 100). Output Output a single integer β€” the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image>
2
9
#include <bits/stdc++.h> using namespace std; const long long N = 1e10 + 0; deque<long long> v, vc; long long cnt, ans, sum, n, a; map<long long, long long> mp; void DNM() { cin >> n; for (long long i = 0; i < n; i++) { cin >> a; v.push_back(a); } sort(v.begin(), v.end()); for (long long i = 0; i < v.size(); i++) { if (mp[i] == 1) continue; cnt = 1; for (long long j = i + 1; j < v.size(); j++) { if (mp[j] == 0 and cnt <= v[j]) cnt++, mp[j] = 1; } ans++; } cout << ans << endl; } int main() { ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL); int Qu_l_uQ = 1; while (Qu_l_uQ--) DNM(); }
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=list(map(int,input().split())) arr.sort() for k in range(1,n+1): i=0 v=0 ok=True while i<n: for j in range(i,min(i+k,n)): if arr[j]<v: ok=False break i+=k v+=1 if ok: print(k) exit()
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.awt.Point; import java.io.*; import java.lang.reflect.Array; import java.math.BigInteger; import java.util.*; import static java.lang.Math.*; public class Solution implements Runnable { BufferedReader in; PrintWriter out; StringTokenizer tok = new StringTokenizer(""); public static void main(String[] args) { new Thread(null, new Solution(), "", 256 * (1L << 20)).start(); } public void run() { try { long t1 = System.currentTimeMillis(); if (System.getProperty("ONLINE_JUDGE") != null) { 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"); out = new PrintWriter(System.out); } Locale.setDefault(Locale.US); solve(); in.close(); out.close(); long t2 = System.currentTimeMillis(); System.err.println("Time = " + (t2 - t1)); } catch (Throwable t) { t.printStackTrace(System.err); System.exit(-1); } } String readString() throws IOException { while (!tok.hasMoreTokens()) { tok = new StringTokenizer(in.readLine()); } return tok.nextToken(); } int readInt() throws IOException { return Integer.parseInt(readString()); } long readLong() throws IOException { return Long.parseLong(readString()); } double readDouble() throws IOException { return Double.parseDouble(readString()); } // solution void solve() throws IOException { int n = readInt(); int[] mas = new int[n]; for(int i = 0; i<n; i++){ mas[i] = readInt(); } Arrays.sort(mas); for(int ans = 1;;ans++){ int[] can = new int[ans]; for(int i = 0; i<ans; i++) can[i] = 100000; boolean good = true; for(int i = 0; i<n; i++){ if(can[i%ans] < 1){ good = false; break; } can[i%ans] = Math.min(can[i%ans] - 1, mas[n - 1 - i]); } if(good){ out.println(ans); break; } } } }
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.*; // import java.lang.*; import java.io.*; // THIS TEMPLATE MADE BY AKSH BANSAL. public class Solution { 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; } } public static void main(String[] args) throws IOException { FastReader sc = new FastReader(); PrintWriter out = new PrintWriter(System.out); // ________________________________ // int t = sc.nextInt(); // StringBuilder output = new StringBuilder(); // while (t-- > 0) { // } // out.println(output); // _______________________________ int n = sc.nextInt(); int[] arr = new int[n]; for(int i=0;i<n;i++){ arr[i] = sc.nextInt(); } out.println(solver(n,arr)); // ________________________________ out.flush(); } public static int solver(int len, int[] arr) { int res = 1; int[] freq = new int[101]; for(int i: arr){ freq[i]++; } for(int i=0;i<=100;i++){ if(i!=0)freq[i]+=freq[i-1]; res = Math.max(res, (freq[i]+i)/(i+1)); } return 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 N, S[105]; bool feasible(int pile) { priority_queue<int> pq; for (int i = 0; i < pile; ++i) pq.push(S[N - i - 1]); for (int i = N - pile - 1; i >= 0; --i) { int lim = pq.top(); pq.pop(); if (lim <= 0) return false; pq.push(min(lim - 1, S[i])); } return true; } int main() { cin >> N; for (int i = 0; i < N; ++i) cin >> S[i]; sort(S, S + N); int left = 1, right = N; int ans; while (left <= right) { int piles = (left + right) >> 1; if (feasible(piles)) { ans = piles; right = piles - 1; } else { left = piles + 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
def check(s, k): for i in xrange(len(s)): if s[i] < i/k: return False return True def f(n): s = sorted(map(int, raw_input().split())) start, end = 1, n while start < end: mid = (start+end)/2 if check(s, mid): end = mid else: start = mid+1 return (start+end)/2 print f(int(raw_input()))
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.util.*; public class C { public static void main(String[] args) { Scanner s = new Scanner(System.in); int n = s.nextInt(); Vector<Pile> list = new Vector<Pile>(); for(int i=0; i<n; i++) list.addElement(new Pile(1, s.nextInt())); Collections.sort(list); int count = 0; while(list.size() != 0) { Pile temp = list.elementAt(0); list.removeElementAt(0); int height = temp.height; boolean check = false; for(int i=0; i<list.size(); i++) { if(list.elementAt(i).capacity >= height) { list.elementAt(i).capacity = temp.capacity; list.elementAt(i).height += height; check = true; break; } } if(!check) count++; Collections.sort(list); } System.out.println(count); } } class Pile implements Comparable<Pile> { int height, capacity; public Pile(int h, int c) { height = h; capacity = c; } public int compareTo(Pile p) { if(capacity != p.capacity) return capacity-p.capacity; else return p.height-height; } }
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 heapq #br = open('a.in') f = lambda: map(int, raw_input().strip().split()) n, a, b = f()[0], sorted(f()), [] for i in a: h = next((j for j, k in enumerate(b) if k <= i), None) if h is None: heapq.heappush(b, 1) else: b[h] += 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
//Author: net12k44 import java.io.*; import java.util.*; public class Main{//} static PrintWriter out; static void solve() { int n = in.nextInt(); int a[] = new int [n]; int d[] = new int [n]; for(int i = 0; i < n ;++i) a[i] = in.nextInt(); Arrays.sort(a); int kq = 0; for(int i = 0; i < n; ++i) { boolean ok = false; for(int j = 0; j < kq; ++j) if (d[j] <= a[i]) { d[j]++; ok = true; break; } if (!ok) d[kq++] = 1; } out.println(kq); } public static void main (String[] args) throws java.lang.Exception { long startTime = System.currentTimeMillis(); out = new PrintWriter(System.out); solve(); //out.println((String.format("%.2f",(double)(System.currentTimeMillis()-startTime)/1000))); out.close(); } static class in { static BufferedReader reader = new BufferedReader( new InputStreamReader(System.in) ) ; static StringTokenizer tokenizer = new StringTokenizer(""); static String next() { while ( !tokenizer.hasMoreTokens() ) try { tokenizer = new StringTokenizer( reader.readLine() ); } catch (IOException e){ throw new RuntimeException(e); } return tokenizer.nextToken(); } static int nextInt() { return Integer.parseInt( next() ); } static 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
import java.util.Arrays; import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner scan = new Scanner(System.in); int n,count=1; n=scan.nextInt(); int[] boxes = new int[n]; for(int i=0;i<n;i++){ boxes[i]=scan.nextInt(); } Arrays.sort(boxes); for(int i=1;i<n;i++){ if((i)/count>boxes[i]) count++; } System.out.println(count); scan.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.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.util.Arrays; import java.util.InputMismatchException; public class A228{ void solve() { int n = ni(); int[] a = ia(n); Arrays.sort(a); for(int i=0;i<n;i++) { if(a[i] < 0) continue; int j = i+1; int p = i; int sz = 1; while(j<n) { while(j<n && a[j]<sz) j++; if(j==n) break; a[p] = -1; p = j; j++; sz++; } a[p] = -2; } int cn = 0; for(int k : a) if(k==-2) cn++; out.println(cn); } public static void main(String[] args){new A228();} private byte[] bufferArray = new byte[1024]; private int bufLength = 0; private int bufCurrent = 0; InputStream inputStream; PrintWriter out; public A228() { inputStream = System.in; out = new PrintWriter(System.out); solve(); out.flush(); } int nextByte() { if(bufLength==-1) throw new InputMismatchException(); if(bufCurrent>=bufLength) { bufCurrent = 0; try {bufLength = inputStream.read(bufferArray);} catch(IOException e) { throw new InputMismatchException();} if(bufLength<=0) return -1; } return bufferArray[bufCurrent++]; } boolean isSpaceChar(int x) {return (x<33 || x>126);} boolean isDigit(int x) {return (x>='0' && x<='9');} int nextNonSpace() { int x; while((x=nextByte())!=-1 && isSpaceChar(x)); return x; } int ni() { long ans = nl(); if ( Integer.MIN_VALUE <= ans && ans <= Integer.MAX_VALUE ) return (int)ans; throw new InputMismatchException(); } long nl() { long ans = 0; boolean neg = false; int x = nextNonSpace(); if(x=='-') { neg = true; x = nextByte(); } while(!isSpaceChar(x)) { if(isDigit(x)) { ans = ans*10 + x -'0'; x = nextByte(); } else throw new InputMismatchException(); } return neg ? -ans:ans; } String ns() { StringBuilder sb = new StringBuilder(); int x = nextNonSpace(); while(!isSpaceChar(x)) { sb.append((char)x); x = nextByte(); } return sb.toString(); } char nc() { return (char)nextNonSpace();} double nd() { return (double)Double.parseDouble(ns()); } char[] ca() { return ns().toCharArray();} char[] ca(int n) { char[] ans = new char[n]; int p =0; int x = nextNonSpace(); while(p<n) { ans[p++] = (char)x; x = nextByte(); } return ans; } int[] ia(int n) { int[] ans = new int[n]; for(int i=0;i<n;i++) ans[i]=ni(); return ans; } }
JAVA
389_C. Fox and Box Accumulation
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≀ n ≀ 100). The next line contains n integers x1, x2, ..., xn (0 ≀ xi ≀ 100). Output Output a single integer β€” the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image>
2
9
#include <bits/stdc++.h> using namespace std; int main() { int n; cin >> n; vector<int> vec(n); int res = 0; for (int i = 0; i < n; i++) cin >> vec[i]; sort(vec.begin(), vec.end()); int num = 0; bool vis[110] = {0}; for (int a = 0; a < n; a++) { bool ok = 0; num = 0; for (int i = 0; i < n; i++) { if (vis[i]) continue; if (vec[i] < num) continue; ok = 1; num++; vis[i] = 1; } res += ok; } cout << res << 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 ri() { int r; cin >> r; return r; } unsigned int rui() { unsigned int r; cin >> r; return r; } long long rl() { long long r; cin >> r; return r; } unsigned long long rul() { unsigned long long r; cin >> r; return r; } double rd() { double r; cin >> r; return r; } string rss() { string r; cin >> r; return r; } string rs() { string r; getline(cin, r); return r; } vector<string> rvs(int n) { assert(n); vector<string> r; for (int i = 0; i < n; ++i) { string s = rs(); while (s.empty()) s = rs(); r.push_back(s); } return r; } vector<int> rvi(int n) { assert(n); vector<int> r; for (int i = 0; i < n; ++i) r.push_back(ri()); return r; } vector<unsigned int> rvui(int n) { assert(n); vector<unsigned int> r; for (int i = 0; i < n; ++i) r.push_back(rui()); return r; } vector<long long> rvl(int n) { assert(n); vector<long long> r; for (int i = 0; i < n; ++i) r.push_back(rl()); return r; } vector<unsigned long long> rvul(int n) { assert(n); vector<unsigned long long> r; for (int i = 0; i < n; ++i) r.push_back(rul()); return r; } vector<double> rvd(int n) { assert(n); vector<double> r; for (int i = 0; i < n; ++i) r.push_back(rd()); return r; } int main() { int n = ri(); auto v = rvi(n); sort((v).begin(), (v).end()); size_t cnt = 0; while (!v.empty()) { ++cnt; int cur = 1; v.erase(v.begin()); vector<int>::iterator it; while ((it = lower_bound((v).begin(), (v).end(), cur)) != v.end()) { ++cur; v.erase(it); } } cout << cnt << endl; return 0; }
CPP
389_C. Fox and Box Accumulation
Fox Ciel has n boxes in her room. They have the same size and weight, but they might have different strength. The i-th box can hold at most xi boxes on its top (we'll call xi the strength of the box). Since all the boxes have the same size, Ciel cannot put more than one box directly on the top of some box. For example, imagine Ciel has three boxes: the first has strength 2, the second has strength 1 and the third has strength 1. She cannot put the second and the third box simultaneously directly on the top of the first one. But she can put the second box directly on the top of the first one, and then the third box directly on the top of the second one. We will call such a construction of boxes a pile. <image> Fox Ciel wants to construct piles from all the boxes. Each pile will contain some boxes from top to bottom, and there cannot be more than xi boxes on the top of i-th box. What is the minimal number of piles she needs to construct? Input The first line contains an integer n (1 ≀ n ≀ 100). The next line contains n integers x1, x2, ..., xn (0 ≀ xi ≀ 100). Output Output a single integer β€” the minimal possible number of piles. Examples Input 3 0 0 10 Output 2 Input 5 0 1 2 3 4 Output 1 Input 4 0 0 0 0 Output 4 Input 9 0 1 0 2 0 1 1 2 10 Output 3 Note In example 1, one optimal way is to build 2 piles: the first pile contains boxes 1 and 3 (from top to bottom), the second pile contains only box 2. <image> In example 2, we can build only 1 pile that contains boxes 1, 2, 3, 4, 5 (from top to bottom). <image>
2
9
import java.io.OutputStream; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.util.Arrays; import java.io.IOException; import java.util.Random; import java.io.UncheckedIOException; import java.util.AbstractMap; import java.util.TreeMap; import java.io.Closeable; import java.util.Map; import java.io.Writer; import java.io.OutputStreamWriter; import java.util.Comparator; import java.io.InputStream; /** * Built using CHelper plug-in * Actual solution is at the top */ public class Main { public static void main(String[] args) throws Exception { Thread thread = new Thread(null, new TaskAdapter(), "", 1 << 29); thread.start(); thread.join(); } static class TaskAdapter implements Runnable { @Override public void run() { InputStream inputStream = System.in; OutputStream outputStream = System.out; FastInput in = new FastInput(inputStream); FastOutput out = new FastOutput(outputStream); AFoxAndBoxAccumulation solver = new AFoxAndBoxAccumulation(); solver.solve(1, in, out); out.close(); } } static class AFoxAndBoxAccumulation { public void solve(int testNumber, FastInput in, FastOutput out) { int n = in.ri(); int[] x = in.ri(n); Randomized.shuffle(x); Arrays.sort(x); MultiSet<Integer> set = new MultiSet<>(); for (int t : x) { Integer last = set.floor(t); if (last == null) { set.add(1); } else { set.remove(last); set.add(last + 1); } } out.println(set.size()); } } static class FastInput { private final InputStream is; private byte[] buf = new byte[1 << 13]; private int bufLen; private int bufOffset; private int next; public FastInput(InputStream is) { this.is = is; } public void populate(int[] data) { for (int i = 0; i < data.length; i++) { data[i] = readInt(); } } private int read() { while (bufLen == bufOffset) { bufOffset = 0; try { bufLen = is.read(buf); } catch (IOException e) { bufLen = -1; } if (bufLen == -1) { return -1; } } return buf[bufOffset++]; } public void skipBlank() { while (next >= 0 && next <= 32) { next = read(); } } public int ri() { return readInt(); } public int[] ri(int n) { int[] ans = new int[n]; populate(ans); return ans; } public int readInt() { int sign = 1; skipBlank(); if (next == '+' || next == '-') { sign = next == '+' ? 1 : -1; next = read(); } int val = 0; if (sign == 1) { while (next >= '0' && next <= '9') { val = val * 10 + next - '0'; next = read(); } } else { while (next >= '0' && next <= '9') { val = val * 10 - next + '0'; next = read(); } } return val; } } static class FastOutput implements AutoCloseable, Closeable, Appendable { private static final int THRESHOLD = 32 << 10; private final Writer os; private StringBuilder cache = new StringBuilder(THRESHOLD * 2); public FastOutput append(CharSequence csq) { cache.append(csq); return this; } public FastOutput append(CharSequence csq, int start, int end) { cache.append(csq, start, end); return this; } private void afterWrite() { if (cache.length() < THRESHOLD) { return; } flush(); } public FastOutput(Writer os) { this.os = os; } public FastOutput(OutputStream os) { this(new OutputStreamWriter(os)); } public FastOutput append(char c) { cache.append(c); afterWrite(); return this; } public FastOutput append(int c) { cache.append(c); afterWrite(); return this; } public FastOutput println(int c) { return append(c).println(); } public FastOutput println() { return append('\n'); } public FastOutput flush() { try { // boolean success = false; // if (stringBuilderValueField != null) { // try { // char[] value = (char[]) stringBuilderValueField.get(cache); // os.write(value, 0, cache.length()); // success = true; // } catch (Exception e) { // } // } // if (!success) { os.append(cache); // } os.flush(); cache.setLength(0); } catch (IOException e) { throw new UncheckedIOException(e); } return this; } public void close() { flush(); try { os.close(); } catch (IOException e) { throw new UncheckedIOException(e); } } public String toString() { return cache.toString(); } } static class Randomized { public static void shuffle(int[] data) { shuffle(data, 0, data.length - 1); } public static void shuffle(int[] data, int from, int to) { to--; for (int i = from; i <= to; i++) { int s = nextInt(i, to); int tmp = data[i]; data[i] = data[s]; data[s] = tmp; } } public static int nextInt(int l, int r) { return RandomWrapper.INSTANCE.nextInt(l, r); } } static class MultiSet<T> { private TreeMap<T, Integer> map; private int size; public MultiSet(Comparator<T> comp) { this.map = new TreeMap<>(comp); } public MultiSet() { this.map = new TreeMap<>(); } public int size() { return size; } public void add(T key) { update(key, map.getOrDefault(key, 0), +1); } public void remove(T key) { update(key, map.getOrDefault(key, 0), -1); } public T floor(T x) { return map.floorKey(x); } public void update(T key, int old, int mod) { int cnt = old + mod; size += mod; if (cnt == 0) { map.remove(key); } else { map.put(key, cnt); } } public String toString() { return map.toString(); } } static class RandomWrapper { private Random random; public static final RandomWrapper INSTANCE = new RandomWrapper(); public RandomWrapper() { this(new Random()); } public RandomWrapper(Random random) { this.random = random; } public RandomWrapper(long seed) { this(new Random(seed)); } public int nextInt(int l, int r) { return random.nextInt(r - l + 1) + l; } } }
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[41111], n, was[41111], cnt; int main(void) { cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; sort(a, a + n); int ans = 0; while (cnt < n) { int x = 0; for (int i = 0; i < n; i++) if (was[i] == 0 && x <= a[i]) x++, was[i] = 1; cnt += x, ans++; } 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
def go(): n = int(input()) a = [int(i) for i in input().split(' ')] a.sort() o = 1 for i in range(n): if(a[i] < i // o): o += 1 return o print(go())
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 static java.lang.Math.*; import static java.lang.System.currentTimeMillis; import static java.lang.System.exit; import static java.lang.System.arraycopy; import static java.util.Arrays.sort; import static java.util.Arrays.binarySearch; import static java.util.Arrays.fill; import java.util.*; import java.io.*; public class Main { public static void main(String[] args) throws IOException { try { if (new File("input.txt").exists()) System.setIn(new FileInputStream("input.txt")); } catch (SecurityException e) { } new Main().run(); } BufferedReader in; PrintWriter out; StringTokenizer st = new StringTokenizer(""); private void run() throws IOException { in = new BufferedReader(new InputStreamReader(System.in)); out = new PrintWriter(System.out); solve(); in.close(); out.close(); } private void solve() throws IOException { int n = nextInt(); int[]x = new int[n]; for(int i = 0; i < n; i++) x[i] = nextInt(); sort(x); boolean []used = new boolean[n]; int ans = 0; for(int iter = 0; iter < n; iter++){ int st = 0; while(st < n && used[st]) st++; if(st == n) break; used[st] = true; int w = 1; for(int j = st + 1; j < n; j++){ if(x[j] >= w && !used[j]){ used[j] = true; w++; // System.err.println(j); } } ans++; } out.println(ans); } String nextToken() throws IOException { while (!st.hasMoreTokens()) st = new StringTokenizer(in.readLine()); return st.nextToken(); } int nextInt() throws IOException { return Integer.parseInt(nextToken()); } long nextLong() throws IOException { return Long.parseLong(nextToken()); } double nextDouble() throws IOException { return Double.parseDouble(nextToken()); } String nextLine() throws IOException { st = new StringTokenizer(""); return in.readLine(); } boolean EOF() throws IOException { while (!st.hasMoreTokens()) { String s = in.readLine(); if (s == null) return true; st = new StringTokenizer(s); } return false; } }
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.lang.*; public class Accumulation { public static void main(String[] args) throws java.lang.Exception { InputStream inputStream = System.in; OutputStream outputStream = System.out; InputReader in = new InputReader(inputStream); PrintWriter out = new PrintWriter(outputStream); TaskA solver = new TaskA(); solver.solve(in, out); out.close(); } } class TaskA { public void solve(InputReader in, PrintWriter out) { int n = in.nextInt(), m = 0; int[] a = new int[n]; int i, j, k; for (i=0; i<n; ++i) a[i] = in.nextInt(); Arrays.sort(a); i = 0; while (i < n) { j = i++; while (i<n && a[i]==a[j]) ++i; k = a[j] + 1; if (k*m < i) { m += (i - k * m + k-1)/k; } } out.println(m); } } class InputReader { public BufferedReader reader; public StringTokenizer tokenizer; public InputReader(InputStream stream) { reader = new BufferedReader(new InputStreamReader(stream), 32768); tokenizer = null; } public String next() { while (tokenizer==null || !tokenizer.hasMoreTokens()) { try { tokenizer = new StringTokenizer(reader.readLine()); } catch (IOException e) { throw new RuntimeException(e); } } return tokenizer.nextToken(); } public int nextInt() { return Integer.parseInt(next()); } public long nextLong() { return Long.parseLong(next()); } }
JAVA