F - 斓少摘苹果
2017-04-15 20:41
85 查看
斓少家的院子里有NN棵苹果树,每到秋天树上就会结出FiFi个苹果。
苹果成熟的时候,斓少就会跑去摘苹果。
斓少摘苹果的方式非常的奇特,每次最多可以选择MM个苹果并摘下来。
但是摘下来的苹果两两一定不是来自同一棵树,问斓少最少摘多少次,才能使得每个苹果都被摘下来呢?
Input
第一行输入一个数NN和MM(1≤M≤N≤1061≤M≤N≤106),代表苹果树的数量,和斓少每次最多摘多少个。
第二行输入NN个数,第ii个数FiFi(0≤Fi≤1060≤Fi≤106)代表这一棵树上一共有多少个苹果
Output
输出一个数字,表示最少选择次数
Sample Input
5 3
3 2 3 2 4
Sample Output
5
Hint
样例可以选 (1,3,5) (2,3,5) (1,4,5) (1,2,5) (3,4) 共5次
苹果成熟的时候,斓少就会跑去摘苹果。
斓少摘苹果的方式非常的奇特,每次最多可以选择MM个苹果并摘下来。
但是摘下来的苹果两两一定不是来自同一棵树,问斓少最少摘多少次,才能使得每个苹果都被摘下来呢?
Input
第一行输入一个数NN和MM(1≤M≤N≤1061≤M≤N≤106),代表苹果树的数量,和斓少每次最多摘多少个。
第二行输入NN个数,第ii个数FiFi(0≤Fi≤1060≤Fi≤106)代表这一棵树上一共有多少个苹果
Output
输出一个数字,表示最少选择次数
Sample Input
5 3
3 2 3 2 4
Sample Output
5
Hint
样例可以选 (1,3,5) (2,3,5) (1,4,5) (1,2,5) (3,4) 共5次
#include <cstdio> #include <cstring> #include <queue> #include <stack> #include <cmath> #include <algorithm> using namespace std; main() { long long n,m; scanf("%lld%lld",&n,&m); long long i,max=1,sum=0; long long a[1000000]; for(i=0;i<n;i++) { scanf("%lld",&a[i]); if(a[i]>max) { max=a[i]; } sum+=a[i]; } long long ans; if(sum%m==0) ans = sum/m; else ans = sum/m + 1; if(n <= m) printf("%lld\n",max); else printf("%lld",ans); return 0; }
相关文章推荐