E. Colored Balls
time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

There are n boxes with colored balls on the table. Colors are numbered from 1 to ni-th box contains ai 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 a1, a2, ... , an (1 ≤ ai ≤ 109).

Output

Print one integer number — the minimum possible number of sets.

Examples
input
3
4 7 8
output
5
input
2
2 7
output
4
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.

【分析】

  先%一下大颓果。。

  这种题自己想分配方法都要对拍一下验证啊不然很容易错。。

  假设你分成x和x+1,对于某个A来说,判断是否成立的条件是A mod x <= [A / x] 或者 A mod (x+1)==0嘛。。

  后面那个直接判断就好了,考虑前面那个代表什么。

  就是A-[A/x]*x<=[A/x]

  即A/(x+1)<=[A/x] 即 [A/(x+1)]<[A/x]

  就是说A/(x+1)和A/x要不一样。

  我们去取最小的A,不同的A/x 只有2根号n个,枚举然后for一遍判断就好了。

  然后你求出x最大多少,算ans。【我就是这里错了TAT

  若ans%(x+1)==0 ,直接分成x+1份。

  否则先分成x份,A%x放入每堆中,剩下可能还有很多堆x,每(x+1)堆x的可以变成x堆(x+1)的,所以减掉 剩下的/(x+1),求出答案即可。

  时间(根号A * n)

 #include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define Maxn 510
#define INF 0x7fffffff
#define LL long long int mymin(int x,int y) {return x<y?x:y;}
int mymax(int x,int y) {return x>y?x:y;} int a[Maxn],n; bool check(int x)
{
for(int i=;i<=n;i++)
{
bool p=;
if(a[i]%x==||a[i]%(x+)==||a[i]/x!=a[i]/(x+)) p=;
if(!p) return ;
}
return ;
} int main()
{
// int T;
// scanf("%d",&T);
// while(T--)
{
scanf("%d",&n);
for(int i=;i<=n;i++) scanf("%d",&a[i]);
int mn=INF,ans=;
for(int i=;i<=n;i++) mn=mymin(mn,a[i]);
for(int i=mn;i>=;)
{
if(i<ans) break;
int x=mn/i,r=mn/(x+);
if(check(i)) ans=mymax(ans,i);
i=r;
}
for(int i=;i<=mn;)
{
if(mn/i<ans) break;
int x=mn/i,r=mn/x;
if(check(x)) ans=mymax(ans,x);
else if(check(x-)) ans=mymax(ans,x-);
i=r+;
}
LL sm=;
for(int i=;i<=n;i++)
{
if(a[i]%(ans+)==) sm+=a[i]/(ans+);
else
{
int xx=a[i]/ans,yy=a[i]%ans;
// xx-=yy;
sm+=xx-(xx-yy)/(ans+);
}
// sm+=(a[i]/(ans+1))+(a[i]%(ans+1)!=0);
}
printf("%I64d\n",sm);
}
return ;
}

2017-04-19 10:02:16

【CF contest/792/problem/E】的更多相关文章

  1. 【cf contest 1119 H】Triple

    题目 给出 \(n\) 个三元组\(\{ a_i,b_i,c_i \}\)和\(x,y,z\): 将每个三元组扩展成(\(x\)个\(a_i\),\(y\)个\(b_i\),\(z\)个\(c_i\) ...

  2. 【cf contest 1119 G】Get Ready for the Battle

    题目 你有\(n\)个士兵,需要将他们分成\(m\)组,每组可以为0: 现在这些士兵要去攻打\(m\)个敌人,每个敌人的生命值为\(hp_i\) : 一轮游戏中一组士兵选定一个攻打的敌人,敌人生命值- ...

  3. 【CF 676B Pyramid of Glasses】模拟,递归

    题目链接:http://codeforces.com/problemset/problem/676/B 题意:一个n层的平面酒杯金字塔,如图,每个杯子的容量相同.现在往最顶部的一个杯子倒 t 杯酒,求 ...

  4. 【CF Round 434 A. k-rounding】

    Time limit per test1 second memory limit per test 256 megabytes input standard input output standard ...

  5. 【CF Round 429 B. Godsend】

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  6. 【CF Manthan, Codefest 17 B】Marvolo Gaunt's Ring

    [链接]h在这里写链接 [题意] 给你n个数字; 让你在其中找出三个数字i,j,k(i<=j<=k); 使得p*a[i]+q*a[j]+r*a[k]最大; [题解] /*     有一个要 ...

  7. 【CF Manthan, Codefest 17 A】Tom Riddle's Diary

    [链接]h在这里写链接 [题意] 在这里写题意 [题解] /* Be careful. 二重循环枚举 */ [错的次数] 0 [反思] 在这了写反思 [代码] #include <bits/st ...

  8. 【luogu P4137 Rmq Problem / mex】 题解

    题目链接:https://www.luogu.org/problemnew/show/P4137 求区间内最大没出现过的自然数 在add时要先判断会不会对当前答案产生影响,如果有就去找下一个答案. # ...

  9. 【CF edu 30 A. Chores】

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

随机推荐

  1. 千里之行始于足下,node.js 资源中文导航

    响应@jiyinyiyong 号召,cnodjs 好的资源蛮多的,的确欠缺分类,在一群FAQ中,的确很容易沉下去,根据自己对node.js的理解,做成一个资源导航,PS:如果觉得合适,希望能够合并的c ...

  2. Web 开发人员需知的 Web 缓存知识

    今天踩着前辈们的肩膀,再次把这篇文章翻译整理下.一来让自己对web缓存的理解更深刻些,二来让大家注意力稍稍转移下,不要整天HTML5, 面试题啊叨啊叨的~~ 什么是Web缓存,为什么要使用它? Web ...

  3. macbook 安装任意来源

    sudo spctl --master-disable Comand+r Csrutil disable Reboot

  4. Mysql储存过程8:repeat循环

    语法: repeat SQL until 条件 end repeat; 就是相当于其他语言中的: do{ # }while(); mysql> create procedure p1p() -& ...

  5. 有关mysql的innodb_flush_log_at_trx_commit参数【转】

    一.参数解释 0:log buffer将每秒一次地写入log file中,并且log file的flush(刷到磁盘)操作同时进行.该模式下在事务提交的时候,不会主动触发写入磁盘的操作. 1:每次事务 ...

  6. mac下 mysql / nginx 问题总汇

    "ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)&q ...

  7. 理解HTTP幂等性(转)

    原文链接:http://www.cnblogs.com/weidagang2046/archive/2011/06/04/2063696.html

  8. 转 proc文件

    /proc 是一个伪文件系统, 被用作内核数据结构的接口, 而不仅仅是解释说明/dev/kmem. /proc 里的大多数文件都是只读的, 但也可以通过写一些文件来改变内核变量. 下面对整个 /pro ...

  9. 模块定义文件.def

    一作用 DLL中导出函数的声明有两种方式:一种为在函数声明中加上__declspec(dllexport),这里不再举例说明:另外一种方式是采用模块定义(.def) 文件声明,.def文件为链接器提供 ...

  10. json数据操作

    <!DOCTYPE HTML> <html> <head> <meta charset="utf-8"> <title> ...