【Codeforces 1118D1】Coffee and Coursework (Easy version)
【链接】 我是链接,点我呀:)
【题意】
题意
【题解】
从小到大枚举天数.
然后贪心地,从大到小分配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)的更多相关文章
- 【Codeforces 1108E1】Array and Segments (Easy version)
[链接] 我是链接,点我呀:) [题意] 题意 [题解] 枚举最大值和最小值在什么地方. 显然,只要包含最小值的区间,都让他减少. 因为就算那个区间包含最大值,也无所谓,因为不会让答案变小. 但是那些 ...
- 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 ...
- Coffee and Coursework (Easy version)
Coffee and Coursework (Easy version) time limit per test 1 second memory limit per test 256 megabyte ...
- Codeforces Round #540 (Div. 3)--1118D1 - Coffee and Coursework (Easy version)
https://codeforces.com/contest/1118/problem/D1 能做完的天数最大不超过n,因为假如每天一杯咖啡,每杯咖啡容量大于1 首先对容量进行从大到小的排序, sor ...
- 【Codeforces 1185C2】Exam in BerSU (hard version)
[链接] 我是链接,点我呀:) [题意] 要让前i个数字的和小于等于M. 问你最少要删掉前i-1个数字中的多少个数字,每个询问都是独立的. [题解] ti的范围很小. 所以N*MAX(TI)暴力枚举就 ...
- 【codeforces 415D】Mashmokh and ACM(普通dp)
[codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...
- Coffee and Coursework (Hard Version)
Coffee and Coursework (Hard Version) time limit per test 2.5 seconds memory limit per test 256 megab ...
- 【codeforces 239B】Easy Tape Programming
[题目链接]:http://codeforces.com/contest/239/problem/B [题意] 给你一个长度为n的字符串,只包括'<">'以及数字0到9; 给你q ...
- 【codeforces 816B】Karen and Coffee
[题目链接]:http://codeforces.com/contest/816/problem/B [题意] 给你很多个区间[l,r]; 1<=l<=r<=2e5 一个数字如果被k ...
随机推荐
- Maven package打包webapp项目遇到的问题
环境Java: JDK_1.7.0_79Eclipse: Mars(4.5.0)Maven: 3.3.3最近公司同事重构某Java web项目,完成之后发现部署启动总是不成功 Caused by: o ...
- bzoj 4596: [Shoi2016]黑暗前的幻想乡【容斥原理+矩阵树定理】
真是简单粗暴 把矩阵树定理的运算当成黑箱好了反正我不会 这样我们就可以在O(n^3)的时间内算出一个无向图的生成树个数了 然后题目要求每个工程队选一条路,这里可以考虑容斥原理:全选的方案数-不选工程队 ...
- 51nod 1029 大数除法
1029 大数除法 基准时间限制:4 秒 空间限制:131072 KB 分值: 160 难度:6级算法题 收藏 关注 给出2个大整数A,B,计算A / B和A Mod B的结果. Input 第1 ...
- 递推DP Codeforces Round #260 (Div. 1) A. Boredom
题目传送门 /* DP:从1到最大值,dp[i][1/0] 选或不选,递推更新最大值 */ #include <cstdio> #include <algorithm> #in ...
- TypeError: string indices must be integers, not str
1. TypeError: string indices must be integers, not str 字符串类型取第index个字符的时候,应该传入int而不是str.如 1 a='abcde ...
- <mybatis:scan>与<MapperScannerConfigurer/>
使用Mybatis作为持久层的框架,对dao层的bean对象的注解扫描有两种方式:<mybatis:san>.<MapperScannerConfigurer> 一:<m ...
- url-safe base64 && base64
1: 为什么需要base64? ASCII码一共规定了128个字符的编码,这128个符号,范围在[0,127]之间. 其中,[0,31],及127, 33个属于不可打印的控制字符. 在电子邮件传输信息 ...
- C# 绘图三种方式
如果你想在窗体上进行绘画.通常会使用以下方法. 方法1,利用控件或窗体的paint事件中的painEventArgs private void form1_Paint(object sender, P ...
- HWND CWND 转换
一.区别HWND是句柄,CWnd是MFC窗体类,CWnd中包含HWND句柄成员对象是m_hWnd.HWND是Windows系统中对所有窗口的一种标识,即窗口句柄.这是一个SDK概念. CWnd是M ...
- JavaScipt30(第一个案例)(主要知识点:键盘事件以及transitionend)
今天得到一个github练习项目,是30个原生js写成的小例子,麻雀虽小五脏俱全,现在记录一下第一个. 第一个是键盘按键时页面上对应的键高亮,同时播放音频,松开后不再高亮. 我自己实现了一下,然后查看 ...