【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 ...
随机推荐
- 最短路径(Dijkstra算法)
当用图结构来表示通信.交通等网络,权重代表距离或者成本,寻找最短路径就成为了一个重要的任务. 给定带权网络G=(V;E),源点s,对于其他所有顶点v,寻找s到v的最短路径,连接成一颗最短路径树.可以证 ...
- bzoj4720: [Noip2016]换教室(期望dp)
4720: [Noip2016]换教室 Time Limit: 20 Sec Memory Limit: 512 MBSubmit: 1294 Solved: 698[Submit][Status ...
- 20道spring boot面试题
面试了少量人,简历上都说自己熟习 Spring Boot, 或者者说正在学习 Spring Boot,一问他们时,都只停留在简单的使用阶段,很多东西都不清楚,也让我对面试者大失所望. 下面,我给大家总 ...
- swoole多进程处理产生的问题
以前用swoole的时候,没有涉及到数据库连接,碰到问题没有那么多,后来公司业务原生来写swoole多进程,问题出现很多 1.多进程之间会产生进程隔离,global无效,不能共用一个mysql,red ...
- 题解报告:hdu 1015 Safecracker
Problem Description === Op tech briefing, 2002/11/02 06:42 CST === "The item is locked in a Kl ...
- Jsp四个作用域page、request、session和application的区别
1.简单说 page指当前页面.在一个jsp页面里有效 2.request 指从http请求到服务器处理结束,返回响应的整个过程.在这个过程中使用forward方式跳转多个jsp.在这些页面里你都可 ...
- 08使用NanoPiM1Plus在Android4.4.2下接TF卡
08使用NanoPiM1Plus在Android4.4.2下接TF卡 大文实验室/大文哥 壹捌陆捌零陆捌捌陆捌贰 21504965 AT qq.com 完成时间:2017/12/5 17:51 版本: ...
- <mybatis:scan>与<MapperScannerConfigurer/>
使用Mybatis作为持久层的框架,对dao层的bean对象的注解扫描有两种方式:<mybatis:san>.<MapperScannerConfigurer> 一:<m ...
- 冒泡 [Python]
冒泡Python class BubbleSort: def __init__(self): self.initArr() def initArr(self): self.arrInfo = [60, ...
- 全3D模具设计自动化解決方案