Interviewe
Interviewe |
| Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) |
| Total Submission(s): 945 Accepted Submission(s): 234 |
|
Problem Description
YaoYao has a company and he wants to employ m people recently. Since his company is so famous, there are n people coming for the interview. However, YaoYao is
so busy that he has no time to interview them by himself. So he decides to select exact m interviewers for this task. YaoYao decides to make the interview as follows. First he queues the interviewees according to their coming order. Then he cuts the queue into m segments. The length of each segment is , which means he ignores the rest interviewees (poor guys because they comes late). Then, each segment is assigned to an interviewer and the interviewer chooses the best one from them as the employee.YaoYao’s idea seems to be wonderful, but he meets another problem. He values the ability of the ith arrived interviewee as a number from 0 to 1000. Of course, the better one is, the higher ability value one has. He wants his employees good enough, so the sum of the ability values of his employees must exceed his target k (exceed means strictly large than). On the other hand, he wants to employ as less people as possible because of the high salary nowadays. Could you help him to find the smallest m? |
|
Input
The input consists of multiple cases.
In the first line of each case, there are two numbers n and k, indicating the number of the original people and the sum of the ability values of employees YaoYao wants to hire (n≤200000, k≤1000000000). In the second line, there are n numbers v1, v2, …, vn (each number is between 0 and 1000), indicating the ability value of each arrived interviewee respectively. The input ends up with two negative numbers, which should not be processed as a case. |
|
Output
For each test case, print only one number indicating the smallest m you can find. If you can’t find any, output -1 instead.
|
|
Sample Input
11 300 |
|
Sample Output
3 Hint
We need 3 interviewers to help YaoYao. The first one interviews people from 1 to 3, the second interviews people from 4 to 6, and the third interviews people from 7 to 9. And the people left will be ignored. And the total value you can get is 100+101+100=301>300. |
|
Source
2010 ACM-ICPC Multi-University Training Contest(5)——Host by BJTU
|
|
Recommend
zhengfeng
|
/*
一道一道有毒的题,忘了一种竟然可以n个线段
*/
#include<bits/stdc++.h>
using namespace std;
int d[][];
int n,k,cur,ob,maxn;
void init()
{
for (int j = ; ( << j) < n; j++){
int t = ( << j) - ;
for (int i = ; i+t < n; i++){
d[i][j] = max(d[i][j-], d[i+(<<(j-))][j-]);
}
}
}
inline int RMQ(int a, int b)
{
int l = int(log(double(b-a+))/log(2.0));
return max(d[a][l], d[b+-(<<l)][l]);
}
int main()
{
//freopen("C:\\Users\\acer\\Desktop\\in.txt","r",stdin);
while(scanf("%d%d",&n,&k)&&n>=&&k>=)
{
ob=;
maxn=;
for(int i=;i<n;i++)
{
scanf("%d",&d[i][]);
ob+=d[i][];
maxn=max(maxn,d[i][]);
}
if(ob<=k)
{
puts("-1");
continue;
}
init();//RMQ预处理
/*二分找最小值*/
int ans=n;
for(int m=max(,k/maxn);m<n;m++)
{
cur=;
int t=n/m;//分组的长度
//cout<<"t="<<t<<endl;
for(int i=;i<=m;i++)//枚举的组数
{
cur+=RMQ(t*(i-),t*i-);
//cout<<t*(i-1)+1<<" "<<t*i<<endl;
if(cur>k)
break;
}
if(cur>k)
{
ans=m;
break;
}
}
printf("%d\n",ans);
}
return ;
}
Interviewe的更多相关文章
- HDOJ 3486 Interviewe
人生中第一次写RMQ....一看就知道 RMQ+2分但是题目文不对题....不知道到底在问什么东西....各种WA,TLE,,RE...后就过了果然无论错成什么样都可以过的,就是 上层的样例 啊 I ...
- hdu 3486 Interviewe (RMQ+二分)
Interviewe Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- Interviewe(hdu3486)
Interviewe Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total ...
- HDU 3486 Interviewe
题目大意:给定n个数的序列,让我们找前面k个区间的最大值之和,每个区间长度为n/k,如果有剩余的区间长度不足n/k则无视之.现在让我们找最小的k使得和严格大于m. 题解:二分k,然后求RMQ检验. S ...
- Interviewe HDU - 3486( 暴力rmq)
面试n个人,可以分任意组数,每组选一个,得分总和严格大于k,问最少分几组 就是暴力嘛...想到就去写吧.. #include <iostream> #include <cstdio& ...
- HDU 3486 Interviewe RMQ
题意: 将\(n\)个数分成\(m\)段相邻区间,每段区间的长度为\(\left \lfloor \frac{n}{m} \right \rfloor\),从每段区间选一个最大值,要让所有的最大值之和 ...
- hdu 3484 Interviewe RMQ+二分
#include <cstdio> #include <iostream> #include <algorithm> using namespace std; + ...
- Interviewe HDU - 3486 (ST表+枚举 )(非二分,看下这个数据、)
YaoYao has a company and he wants to employ m people recently. Since his company is so famous, there ...
- 3486 ( Interviewe )RMQ
Problem Description YaoYao has a company and he wants to employ m people recently. Since his company ...
随机推荐
- WebSocket部署服务器外网无法连接解决方案
首先要说的是我遇见的问题: WebSocket connection to 'ws://www.xxxx.com/xxx/xx' failed: Error during WebSocket hand ...
- React的组件用法
React.createClass() 中文翻译 https://discountry.github.io/react/3.4K ( https://doc.react-china.org868 ) ...
- asp.net core权限模块的快速构建
大部分系统都会有权限模块,别人家系统的权限怎么生成的我不知道,我只知道这样做是可以并且挺好的. 文章中只对asp.net core的部分代码进行说明 呃 记录~,mvc版本自行前往仓库查阅 代码中的一 ...
- 说下browserslist
browserslist 是一个开源项目 见到有些package.json里会有如下的配置参数 "browserslist": [ "> 1%", &qu ...
- oracle数据库备份、还原 (如何将Oracle 11g备份的dat文件导入到10g数据库里面)
如何将Oracle 11g备份的dat文件导入到10g数据库里面 解决方法: 导出的时候后面加上目标数据库的版本号 导出: 在SQL plus下执行:create or replace ...
- js中+号的另外一种用法
JavaScript中可以在某个元素前使用 ‘+’ 号,这个操作是将该元素转换成Number类型,如果转换失败,那么将得到 NaN. 所以 +new Date 将会调用 Date.prototype ...
- Jest 单元测试入门
今天,我们要讲的是 Jest 单元测试的入门知识. 为何要进行单元测试? 在学习 Jest 之前,我们需要回答一个问题:为何要进行单元测试?编写单元测试可以给你带来很多好处: 将测试自动化,无需每次都 ...
- 基于C#的BarCode 39实现
一.39条码简介 39码是1974年发展出来的条码系统,是一种可供使用者双向扫瞄的分散式条码,也就是说相临两资料码之间,必须包含一个不具任何意义的空白(或细白,其逻辑值为0),且其具有支援文字的能力, ...
- Uva 3708 Graveyard
题意:在周长为10000的圆上等距分布着n个雕塑.现在又有m个新雕塑加入(位置可以随意放),希望所有n+m个雕塑在圆周上均匀分布. 这就需要移动其中一些原有的雕塑.要求n个雕塑移动的距离最小. (2& ...
- Python多线程练习(threading)
这几天学习python多线程的时候,试了几次thread模块和threading模块,发现thread模块非常的不好用.强烈不建议大家使用thread,建议使用threading模块,此模块对thre ...
, which means he ignores the rest interviewees (poor guys because they comes late). Then, each segment is assigned to an interviewer and the interviewer chooses the best one from them as the employee.