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

【题意】

题意

【题解】

从小到大枚举天数.
然后贪心地,从大到小分配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. 【168】ENVI入门系列

    参考:ENVI-IDL中国的博客 [ENVI入门系列]01.ENVI产品简介与入门 [ENVI入门系列]02.自定义坐标系(北京54.西安80.2000坐标系) [ENVI入门系列]03.基于自带定位 ...

  2. 阿里云短信验证_基于阿里云OpenAPI实现

    阿里云短信服务 背景简介: 短信验证以及短信通知,目前已经应用的非常广泛,最近因项目需要,需要将原来的短信接口换成阿里云的的短信服务,原项目集成的短信服务能够实现短信的发送以及短信的验证整个过程,简单 ...

  3. 区间DP UVA 1351 String Compression

    题目传送门 /* 题意:给一个字符串,连续相同的段落可以合并,gogogo->3(go),问最小表示的长度 区间DP:dp[i][j]表示[i,j]的区间最小表示长度,那么dp[i][j] = ...

  4. 在 NodeJs 上搭建 React 开发环境

    步骤: 1. 安装 nodejs :根据你的 Windows 类型(x86或x64)下载相应的安装包进行安装.安装完成后,可以在任一目录下打开 cmd 窗口并运行 node -v 命令,如果显示 no ...

  5. TensorFlow---image recognition--classify_image运行、文件说明与错误(路径)解决

    tutorial系列mnist已经玩过了,这篇玩一下 classify_image,其实就是image label.模型已经训练好的了,直接下载下来在.pb文件中. 本机环境: Win10 + Pyt ...

  6. JavaScript相关技术学习

    百度前端技术学院 http://ife.baidu.com/task/all 框架 JQuery 简单Web论坛  https://github.com/huanshen/web-bbs http:/ ...

  7. oracle 用sql语句管理数据库

    基础sql语句 创建数据库 :create database database_name; 创建表:create table(字段名 字段类型 字段为空约束 ,字段名 字段类型 字段为空约束,,,, ...

  8. @objc and dynamic

      @objc and dynamic Objective-C runtime visibility and the depths of dynamic dispatch in the modern ...

  9. 基于 CentOS 搭建Seafile个人网盘

    一.安装 Seafile 安装依赖环境使用 yum 安装 Python 及 MySQL: yum install python python-setuptools python-imaging pyt ...

  10. CLISTCTRL2

    回顾: 刚刚写完,因为是分期写的,所以最初想好好做一下的文章格式半途而废了~说的也许会有点啰嗦,但是所有的基础用到的技术细节应该都用到了. 如果还有什么疑问,请回复留言,我会尽力解答. 如果有错误,请 ...