【链接】 我是链接,点我呀:)

【题意】

题意

【题解】

从小到大枚举天数.
然后贪心地,从大到小分配a[i]到各个天当中。
a[n]分配到第1天,a[n-1]分配到第2天,...然后a[n-x]又分到第一天。
这样能保证优先让大的数字能够无损失地加进去。
从而尽可能快的凑够m天

【代码】

#include <bits/stdc++.h>
using namespace std;
const int N = 100; int n,m;
int a[N+10];
vector<int> v[N+10]; int main(){
ios::sync_with_stdio(0),cin.tie(0);
cin >> n >> m;
for (int i = 1;i <= n;i++){
cin >> a[i];
}
sort(a+1,a+1+n);
reverse(a+1,a+1+n);
for (int day = 1;day <= n;day++){
int cur = 1;
for (int j = 1;j <= day;j++) v[j].clear();
for (int j = 1;j <= n;j++){
int len = v[cur].size();
if (len>0 && a[j]-len<=0){
break;
}
v[cur].push_back(a[j]);
cur++;
if (cur>day) cur = 1;
}
int total = 0;
for (int j = 1;j <= day;j++){
int len = v[j].size();
for (int l = 0;l < len;l++){
int x = v[j][l];
x-=l;
total+=x;
}
}
if (total>=m){
cout<<day<<endl;
return 0;
}
}
cout<<-1<<endl;
return 0;
}

【Codeforces 1118D1】Coffee and Coursework (Easy version)的更多相关文章

  1. 【Codeforces 1108E1】Array and Segments (Easy version)

    [链接] 我是链接,点我呀:) [题意] 题意 [题解] 枚举最大值和最小值在什么地方. 显然,只要包含最小值的区间,都让他减少. 因为就算那个区间包含最大值,也无所谓,因为不会让答案变小. 但是那些 ...

  2. 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 ...

  3. Coffee and Coursework (Easy version)

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

  4. Codeforces Round #540 (Div. 3)--1118D1 - Coffee and Coursework (Easy version)

    https://codeforces.com/contest/1118/problem/D1 能做完的天数最大不超过n,因为假如每天一杯咖啡,每杯咖啡容量大于1 首先对容量进行从大到小的排序, sor ...

  5. 【Codeforces 1185C2】Exam in BerSU (hard version)

    [链接] 我是链接,点我呀:) [题意] 要让前i个数字的和小于等于M. 问你最少要删掉前i-1个数字中的多少个数字,每个询问都是独立的. [题解] ti的范围很小. 所以N*MAX(TI)暴力枚举就 ...

  6. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  7. Coffee and Coursework (Hard Version)

    Coffee and Coursework (Hard Version) time limit per test 2.5 seconds memory limit per test 256 megab ...

  8. 【codeforces 239B】Easy Tape Programming

    [题目链接]:http://codeforces.com/contest/239/problem/B [题意] 给你一个长度为n的字符串,只包括'<">'以及数字0到9; 给你q ...

  9. 【codeforces 816B】Karen and Coffee

    [题目链接]:http://codeforces.com/contest/816/problem/B [题意] 给你很多个区间[l,r]; 1<=l<=r<=2e5 一个数字如果被k ...

随机推荐

  1. 理解javascript中的事件模型

    javascript中有两种事件模型:DOM0,DOM2.而对于这两种的时间模型,我一直不是非常的清楚,现在通过网上查阅资料终于明白了一些. 一.  DOM0级事件模型 DOM0级事件模型是早期的事件 ...

  2. Ubuntu下 VirtualBox的卸载和升级 (转载)

    转载:http://blog.csdn.net/li_hai/article/details/8164744 首先,在终端查看已经安装的VirtualBox的版本: $ dpkg -l 查看到版本号, ...

  3. bzoj 2662: [BeiJing wc2012]冻结【分层图+spfa】

    死活想不到分层图emmm 基本想法是建立分层图,就是建k+1层原图,然后相邻两层之间把原图的边在上一层的起点与下一层的终点连起来,边权为val/2,表示免了这条边的边权,然后答案就是第0层的s到k层的 ...

  4. bzoj 1828: [Usaco2010 Mar]balloc 农场分配【贪心+线段树】

    长得挺唬人的贪心,按照右端点排序,用最小值线段树的询问判断当前牛是否能放进去,能的话更新线段树,ans++ 来自https://www.cnblogs.com/rausen/p/4529245.htm ...

  5. [Swift通天遁地]一、超级工具-(15)使用SCLAlertView制作强大的Alert警告窗口和Input编辑窗口

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  6. Moco模拟服务器post&get请求 (二)

    1.moco启动命令如下:java -jar moco-runner-0.12.0-standalone.jar 协议类型 -p 端口号 -c json配置文件 2.带参数的get请求 [ { &qu ...

  7. SVN版本库的备份及迁移

    备份某个版本库:打开控制台窗口 1.备份某个版本库: svnadmin dump myrepos > dumpfile //将指定的版本库导出成文件dumpfile eg:svnadmin du ...

  8. STL容器迭代过程中删除元素技巧(转)

    1.连续内存序列容器(vector,string,deque) 序列容器的erase方法返回值是指向紧接在被删除元素之后的元素的有效迭代器,可以根据这个返回值来安全删除元素. vector<in ...

  9. mongo 3.4分片集群系列之六:详解配置数据库

    这个系列大致想跟大家分享以下篇章: 1.mongo 3.4分片集群系列之一:浅谈分片集群 2.mongo 3.4分片集群系列之二:搭建分片集群--哈希分片 3.mongo 3.4分片集群系列之三:搭建 ...

  10. 关于vue构建项目的一些指令

    第一步: brew install nodejs(MAC机子下)  Windows直接官网下载对应版本node.js 第二步: 获取nodejs模块安装目录访问权限(Windows系统忽略)sudo ...