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 ![]() 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 ...
随机推荐
- JAVA_String、StringBuilder、StringBuffer区别
String.StringBuilder.StringBuffer均为字符串 类 需要注意的一些问题 String StringBuilder StringBuffer 一旦创建,不能对其内容进行更改 ...
- 深入理解计算机系统chapter9
从概念上来讲:虚拟存储器被组织为一个存放在磁盘上的N个连续的字节大小的单元组成的数组. 磁盘上数组的内容被缓存到主存中 1. 读写内存的安全性 物理内存本身是不限制访问的,任何地址都可以读写,而操作系 ...
- 通过SQL脚本导入数据到不同数据库避免重复导入三种方式
前言 无论何种语言,一旦看见代码中有重复性的代码则想到封装来复用,在SQL同样如此,若我们没有界面来维护而且需要经常进行的操作,我们会写脚本避免下次又得重新写一遍,但是这其中就涉及到一个问题,这个问题 ...
- Judge Route Circle
Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot m ...
- Java高级工程师进阶路线
第一部分:宏观方面 一. JAVA.要想成为JAVA(高级)工程师肯定要学习JAVA.一般的程序员或许只需知道一些JAVA的语法结构就可以应付了.但要成为JAVA(高级) 工程师,您要对JAVA做比较 ...
- mysql explain 分析sql语句
鉴于最近做的事情,需要解决慢sql的问题,现补充一点sql语句性能分析之explain的使用方式! 综合返回数据情况,分析各个参数,可以了解sql 使用方法:explain + sql语句 如 :e ...
- asp.net中利用Jquery+Ajax+Json实现无刷新分页(二)
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="PageTest.aspx.cs ...
- 新版MySql 5.6.20,安装后无法登陆的解决办法
1.按照提示安装好mysql 2.运行cmd 进入mysql的安装目录,我的安装目录C:\Program Files\MySQL\MySQL Server 5.6\bin 输入 cd C:\Progr ...
- WPF控件 在XP下获得焦点有虚线框
所有 Button.ListBox等控件获得焦点时有虚线框.如图:选中523这个按钮就出线虚框. 我在App.xaml中添加适应所有按钮的样式,无效 <Style TargetType=&qu ...
- WPF---Effect效果
在 WPF 中,可以使用 BitmapEffect 对象为每一个 Visual 对象生成各种各样的效果,一个 Visual 对象可以设置一种或多种 BitmapEffect 效果,WPF 内置了几种效 ...