https://codeforces.com/contest/1118/problem/D1

能做完的天数最大不超过n,因为假如每天一杯咖啡,每杯咖啡容量大于1

首先对容量进行从大到小的排序,

sort(num.rbegin(),num.rend());
sort(num.begin(),num.end(),greater<int>());
都可以 然后遍历每一天,当第i天的时候,选出i个容量最大的分配到每一天,如果还没写完,继续选择i个最大的,但是由题意容量需要进行衰减,衰减的量为j/i(也就是把咖啡以i为单位分成了好多组,相当于减去了组号)
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,m;
cin>>n>>m;
vector<int> num(n);
for(int i=;i<n;i++){
cin>>num[i];
}
sort(num.rbegin(),num.rend());
for(int i=;i<=n;i++){
int sum=;
for(int j=;j<n;j++){
sum+=max(num[j]-j/i,);
}
if(sum>=m){
cout<<i<<endl;
return ;
}
}
cout<<-<<endl;
return ;
}

Codeforces Round #540 (Div. 3)--1118D1 - Coffee and Coursework (Easy version)的更多相关文章

  1. Codeforces Round #540 (Div. 3) D1. Coffee and Coursework (Easy version) 【贪心】

    任意门:http://codeforces.com/contest/1118/problem/D1 D1. Coffee and Coursework (Easy version) time limi ...

  2. Codeforces Round #540 (Div. 3)--1118D2 - Coffee and Coursework (Hard Version)

    https://codeforces.com/contest/1118/problem/D2 和easy version的主要区别是,数据增加了. easy version采用的是线性查找,效率低 在 ...

  3. Codeforces Round #540 (Div. 3) D2. Coffee and Coursework (Hard Version) (二分,贪心)

    题意:有\(n\)个数,每次可以选\(k(1\le k\le n)\)个数,并且得到\(a_1+max(0,a_2-1)+max(0,a_3-2)+...+max(0,a_k-k+1)\)的贡献,问最 ...

  4. Codeforces Round #521 (Div. 3) F1. Pictures with Kittens (easy version)

    F1. Pictures with Kittens (easy version) 题目链接:https://codeforces.com/contest/1077/problem/F1 题意: 给出n ...

  5. Codeforces Round #540 (Div. 3)--1118B - Tanya and Candies(easy TL!)

    Tanya has nn candies numbered from 11 to nn. The ii-th candy has the weight aiai. She plans to eat e ...

  6. Codeforces Round #568 (Div. 2) G1. Playlist for Polycarp (easy version) (状压dp)

    题目:http://codeforces.com/contest/1185/problem/G1 题意:给你n给选项,每个选项有个类型和价值,让你选择一个序列,价值和为m,要求连续的不能有两个相同的类 ...

  7. Codeforces Round #575 (Div. 3) D1+D2. RGB Substring (easy version) D2. RGB Substring (hard version) (思维,枚举,前缀和)

    D1. RGB Substring (easy version) time limit per test2 seconds memory limit per test256 megabytes inp ...

  8. Codeforces Round #540 (Div. 3) 部分题解

    Codeforces Round #540 (Div. 3) 题目链接:https://codeforces.com/contest/1118 题目太多啦,解释题意都花很多时间...还有事情要做,就选 ...

  9. Coffee and Coursework (Easy version)

    Coffee and Coursework (Easy version) time limit per test 1 second memory limit per test 256 megabyte ...

随机推荐

  1. 9.12 h5日记

    9.12 知识点补充: 属性继承例子,color.font(font-size/style/family/weight) 1.浏览器的默认字体大小是16px,谷歌浏览器的最小字体是10px,其他浏览器 ...

  2. 循环&信息添加&颜色修改

            #import "AViewController.h" @interface AViewController () <UIActionSheetDelegat ...

  3. python基础易错题

    1.以下代码输入什么: class Person: a = 1 def __init__(self): pass def getAge(self): print(__name__) p = Perso ...

  4. egg 为企业级框架和应用而生, 阿里出品

    https://eggjs.org/zh-cn/intro/ egg 是什么? egg 为企业级框架和应用而生,我们希望由 egg 孕育出更多上层框架,帮助开发团队和开发人员降低开发和维护成本. 设计 ...

  5. hdu2870 Largest Submatrix 单调栈

    描述 就不需要描述了... 题目传送门 题解 被lyd的书的标签给骗了(居然写了单调队列优化dp??)  看了半天没看出来哪里是单调队列dp,表示强烈谴责QAQ w x y z  可以各自 变成a , ...

  6. VS2010配置OpenGL开发环境

    OpenGL(Open Graphics Library)是一个跨编程语言.跨平台的专业图形程序接口.OpenGL是SGI公司开发的一套计算机图形处理系统,是图形硬件的软件接口,任何一个OpenGL应 ...

  7. Codeforces 798C. Mike and gcd problem 模拟构造 数组gcd大于1

    C. Mike and gcd problem time limit per test: 2 seconds memory limit per test: 256 megabytes input: s ...

  8. GBDT-梯度提升树

    随机森林:bagging思想,可以并行,训练集权值相同 可以是分类树,回归树 输出结果(分类树):多数投票         (回归树):均值 减少方差 对异常数据不敏感 GBDT:拟合损失函数 boo ...

  9. 多种方式判断PC端,IOS端,移动端

    1. 通过判断浏览器的userAgent,用正则来判断手机是否是IOS(苹果)和Android(安卓)客户端. var u = navigator.userAgent; var isAndroid = ...

  10. connect: Address is invalid on local machine or port is not valid on remote

    idea 运行正常打成jar包运行提示“connect: Address is invalid on local machine or port is not valid on remote” , 解 ...