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

【题意】

题意

【题解】

从小到大枚举天数.
然后贪心地,从大到小分配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. [App Store Connect帮助]四、添加 App 图标、App 预览和屏幕快照(1)App Store 图标、App 预览和屏幕快照概述

    您可以为您的 App Store 产品页提供有关您 App 的 App Store 图标.三个 App 预览和十张屏幕快照. App Store 图标 您必须提供一个 App Store 图标,用于在 ...

  2. 乐搏讲自动化测试-Python发展背景(1)

    相信小伙伴们都知道,随着软件测试行业的发展和进步自动化测试已经成为必然.在竞争日益激烈的市场环境中也是你升职加薪的利器. 所以,小编决定从今天起!将要系统.连续.高质量的持续更新「整套自动化测试」文章 ...

  3. 【杂文】虚拟键码表(供函数GetAsyncKeyState()使用)

    [杂文]虚拟键码表(供函数GetAsyncKeyState()使用) 什么?你说你不知道 \(GetAsyncKeyState()\) ?\(→\)戳我\(←\) (惊奇的发现 \(0\) ~ \(9 ...

  4. [译]Cookies Without Chocolate Chips

    Cookies Without Chocolate Chips In the HTTP sense, a cookie is a name with an associated value. A se ...

  5. Java 8 (6) Stream 流 - 并行数据处理与性能

    在Java 7之前,并行处理集合非常麻烦.首先你要明确的把包含数据的数据结构分成若干子部分,然后你要把每个子部分分配一个独立的线程.然后,你需要在恰当的时候对他们进行同步来避免竞争,等待所有线程完成. ...

  6. JavaScript 兼容新旧版chrome和firefox的桌面通知

    1.新/旧版本的chrome和firefox都可支持,IE下不支持因此设置为了在最小化窗口处闪烁显示提示文字. 2.设置为提示窗口显示5秒即关闭. 3.可设置图标和点击提示窗口要跳转到的页面(见输入参 ...

  7. 文档声明和HTML样式表

    文档声明 不是注释也不是元素,总是在HTML的第一行 书写格式:<!DOCTYPE HTML> 是用于通知浏览器目前文档正使用哪一个HTML版本(相关属性 lang) 若不写文档声明,浏览 ...

  8. wordpress网站底部的运行时间是怎么设置的?

    别人网站底部显示的网站运行时间是什么设置的?是插件的效果吗? 不用插件,一段JS代码就可以实现同样的效果. 复制如下代码到 footer.php 页脚那里 <span id="runt ...

  9. self和super的区别

    (1)self调用自己方法,super调用父类方法 (2)self是类,super是预编译指令 (3)[self class]和[super class]输出是一样的 ①当使用 self 调用方法时, ...

  10. sql server nullif的使用技巧,除数为零的处理技巧

    在sql server中做除法处理的时候,我们经常需要处理除数为零的情况,因为如果遇到这种情况的时候,sqlserver会抛出遇到以零作除数错误的异常,我们总不希望把这个异常显示给用户吧. 做个会报这 ...