E. Colored Balls

Codeforces
IDCF792E
Time1000ms
Memory256MB
Difficulty
greedymathnumber theory
English · Original
Chinese · Translation
Formal · Original
There are _n_ boxes with colored balls on the table. Colors are numbered from 1 to _n_. _i_\-th box contains _a__i_ balls, all of which have color _i_. You have to write a program that will divide all balls into sets such that: * each ball belongs to exactly one of the sets, * there are no empty sets, * there is no set containing two (or more) balls of different colors (each set contains only balls of one color), * there are no two sets such that the difference between their sizes is greater than 1. Print the minimum possible number of sets. ## Input The first line contains one integer number _n_ (1 ≤ _n_ ≤ 500). The second line contains _n_ integer numbers _a_1, _a_2, ... , _a__n_ (1 ≤ _a__i_ ≤ 109). ## Output Print one integer number — the minimum possible number of sets. [samples] ## Note In the first example the balls can be divided into sets like that: one set with 4 balls of the first color, two sets with 3 and 4 balls, respectively, of the second color, and two sets with 4 balls of the third color.
桌上有 #cf_span[n] 个装有彩球的盒子。颜色编号从 #cf_span[1] 到 #cf_span[n]。第 #cf_span[i] 个盒子包含 #cf_span[ai] 个球,所有球的颜色均为 #cf_span[i]。你需要编写一个程序,将所有球划分为若干集合,使得: 请输出可能的最少集合数量。 第一行包含一个整数 #cf_span[n](#cf_span[1 ≤ n ≤ 500])。 第二行包含 #cf_span[n] 个整数 #cf_span[a1, a2, ... , an](#cf_span[1 ≤ ai ≤ 109])。 请输出一个整数 —— 可能的最少集合数量。 在第一个例子中,球可以被划分为如下集合:一个包含 #cf_span[4] 个第一种颜色球的集合,两个分别包含 #cf_span[3] 和 #cf_span[4] 个第二种颜色球的集合,以及两个各包含 #cf_span[4] 个第三种颜色球的集合。 ## Input 第一行包含一个整数 #cf_span[n](#cf_span[1 ≤ n ≤ 500])。第二行包含 #cf_span[n] 个整数 #cf_span[a1, a2, ... , an](#cf_span[1 ≤ ai ≤ 109])。 ## Output 请输出一个整数 —— 可能的最少集合数量。 [samples] ## Note 在第一个例子中,球可以被划分为如下集合:一个包含 #cf_span[4] 个第一种颜色球的集合,两个分别包含 #cf_span[3] 和 #cf_span[4] 个第二种颜色球的集合,以及两个各包含 #cf_span[4] 个第三种颜色球的集合。
**Definitions** Let $ n \in \mathbb{Z} $ be the number of colors. Let $ A = (a_1, a_2, \dots, a_n) $ be a sequence of positive integers, where $ a_i $ is the number of balls of color $ i $. **Constraints** 1. $ 1 \leq n \leq 500 $ 2. $ 1 \leq a_i \leq 10^9 $ for all $ i \in \{1, \dots, n\} $ **Objective** Find the minimum number of sets $ k \in \mathbb{Z}^+ $ such that the balls can be partitioned into $ k $ sets, where in each set, no two balls have the same color (i.e., each set contains at most one ball of each color).
Samples
Input #1
3
4 7 8
Output #1
5
Input #2
2
2 7
Output #2
4
API Response (JSON)
{
  "problem": {
    "name": "E. Colored Balls",
    "description": {
      "content": "There are _n_ boxes with colored balls on the table. Colors are numbered from 1 to _n_. _i_\\-th box contains _a__i_ balls, all of which have color _i_. You have to write a program that will divide all",
      "description_type": "Markdown"
    },
    "platform": "Codeforces",
    "limit": {
      "time_limit": 1000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "CF792E"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "There are _n_ boxes with colored balls on the table. Colors are numbered from 1 to _n_. _i_\\-th box contains _a__i_ balls, all of which have color _i_. You have to write a program that will divide all...",
      "is_translate": false,
      "language": "English"
    },
    {
      "statement_type": "Markdown",
      "content": "桌上有 #cf_span[n] 个装有彩球的盒子。颜色编号从 #cf_span[1] 到 #cf_span[n]。第 #cf_span[i] 个盒子包含 #cf_span[ai] 个球,所有球的颜色均为 #cf_span[i]。你需要编写一个程序,将所有球划分为若干集合,使得:\n\n请输出可能的最少集合数量。\n\n第一行包含一个整数 #cf_span[n](#cf_span[1 ≤ n ≤ 500])...",
      "is_translate": true,
      "language": "Chinese"
    },
    {
      "statement_type": "Markdown",
      "content": "**Definitions**  \nLet $ n \\in \\mathbb{Z} $ be the number of colors.  \nLet $ A = (a_1, a_2, \\dots, a_n) $ be a sequence of positive integers, where $ a_i $ is the number of balls of color $ i $.\n\n**Con...",
      "is_translate": false,
      "language": "Formal"
    }
  ]
}
Full JSON Raw Segments