首页 技术 正文
技术 2022年11月18日
0 收藏 763 点赞 2,359 浏览 1053 个字

Problem K: Deadline

Time Limit: 2 Sec Memory Limit: 1280 MB

Submit: 1106 Solved: 117

[Submit][Status][Web Board]

Description

There are N bugs to be repaired and some engineers whose abilities are roughly equal. And an engineer can repair a bug per day. Each bug has a deadline A[i].

  Question: How many engineers can repair all bugs before those deadlines at least?  1<=n<= 1e6. 1<=a[i] <=1e9

Input

There are multiply test cases.

   In each case, the first line is an integer N , indicates the number of bugs. The next line is n integers indicates the deadlines of those bugs.

Output

There are one number indicates the answer to the question in a line for each case.

Sample Input

4

1 2 3 4

Sample Output

1

这道题的意思就是每件事都有个deadline,你一天只能做一件事情,我肯定贪心,先做要先完成了事啊,这个需要的程序员最少,可是1e6恐怕会超时的,所以需要对数据进行预处理,大于n的肯定可以做完了,题解上讲可以O(n),用天数前缀和(s[i]-i+1)/i

#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e6 + 5;
int b[MAXN];
int sum[MAXN];
int main()
{
int n;
while (~scanf("%d", &n)) {
int maxA,i,a;
memset(b, 0, sizeof(b));
for (i = 0; i < n; ++i) {
scanf("%d", &a);
if (a > n) {
continue;
}
++b[a];
if (a > maxA) {
maxA = a;
}
}
sum[0] = 0;
int ans = 1;
for (i = 1; i <= maxA; ++i) {
sum[i] = sum[i - 1] + b[i];
ans = max(ans, (sum[i] + i - 1) / i);
} printf("%d\n", ans);
} return 0;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,497
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,910
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,744
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,497
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,135
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,298