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
7 100 7 101 100 100 9 100 100 110 110
-1 -1
 
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
 
Recommend
zhengfeng   |   We have carefully selected several similar problems for you:  2586 2874 2888 3478 3487 

题解 : RMQ

C++代码:

#include<iostream>
#include<cstdio>
#include<string>
#include<cmath>
#include<cstring>
using namespace std;
#define MAXN 200000 +9
#define MAXE 22
int h[MAXN],mmax[MAXN][MAXE];
int N,Q;
int L,R;
void RMQ_ST(){
for(int i=;i<=N;i++){
mmax[i][]=h[i]; }
int end_j=log(N+0.0)/log(2.0);
int end_i;
for(int j=;j<=end_j;j++){
end_i=N+-(<<j);
for(int i=;i<=end_i;i++){
mmax[i][j]=max(mmax[i][j-],mmax[i+(<<(j-))][j-]);
// mmin[i][j]=min(mmin[i][j-1],mmin[i+(1<<(j-1))][j-1]);
}
}
}
int QueryMax(int L,int R){ int k=log(R-L+1.0)/log(2.0);
return max(mmax[L][k],mmax[R-(<<k)+][k]);
} int main(){
while(~scanf("%d%d",&N,&Q)&&(N > || Q > )){
int maxx = ;
for(int i=;i<=N;i++){
scanf("%d",&h[i]);
maxx = max(h[i],maxx);
}
int m = ; RMQ_ST();
m = Q / maxx; int flag = ;
if(m == ) {
m = ;
flag = ;
goto out ;
}
for(;m <= N; m ++){
int res = ;
int sss = ; int s = N / m;
int i = ;
int j = m;
while(j--){
res += QueryMax(i ,i + s- );
i += s;
}
if(res > Q) {
flag = ;
break;
}
}
out :
if(!flag) printf("-1\n");
else
cout << m << endl; } return ;
}

3486 ( Interviewe )RMQ的更多相关文章

  1. hdu 3486 Interviewe (RMQ+二分)

    Interviewe Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total ...

  2. HDU 3486 Interviewe RMQ

    题意: 将\(n\)个数分成\(m\)段相邻区间,每段区间的长度为\(\left \lfloor \frac{n}{m} \right \rfloor\),从每段区间选一个最大值,要让所有的最大值之和 ...

  3. HDOJ 3486 Interviewe

    人生中第一次写RMQ....一看就知道 RMQ+2分但是题目文不对题....不知道到底在问什么东西....各种WA,TLE,,RE...后就过了果然无论错成什么样都可以过的,就是 上层的样例 啊  I ...

  4. HDU 3486 Interviewe

    题目大意:给定n个数的序列,让我们找前面k个区间的最大值之和,每个区间长度为n/k,如果有剩余的区间长度不足n/k则无视之.现在让我们找最小的k使得和严格大于m. 题解:二分k,然后求RMQ检验. S ...

  5. hdu 3484 Interviewe RMQ+二分

    #include <cstdio> #include <iostream> #include <algorithm> using namespace std; + ...

  6. 【转载】图论 500题——主要为hdu/poj/zoj

    转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并 ...

  7. hdu图论题目分类

    =============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...

  8. HDU图论题单

    =============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many ...

  9. [数据结构]RMQ问题小结

    RMQ问题小结 by Wine93 2014.1.14   1.算法简介 RMQ问题可分成以下2种 (1)静态RMQ:ST算法 一旦给定序列确定后就不在更新,只查询区间最大(小)值!这类问题可以用倍增 ...

随机推荐

  1. 【LuoguP2792 】[JSOI2008]小店购物(最小树形图)

    题目链接 题目描述 小店的优惠方案十分简单有趣: 一次消费过程中,如您在本店购买了精制油的话,您购买香皂时就可以享受2.00元/块的优惠价:如果您在本店购买了香皂的话,您购买可乐时就可以享受1.50元 ...

  2. SSH自动登录脚本

    原创转载请注明出处:https://www.cnblogs.com/agilestyle/p/11926792.html vi app-stg.sh #!/usr/bin/expect -f #aut ...

  3. idea 打包model 为jar包

    1,在项目上鼠标右键 --> Open Module Settings 2, Artifacts --> + --> JAR --> From modules with dep ...

  4. 三维显示插件——C++

    Qt 3D 构建自己的C/C++插件开发框架——系列:https://blog.csdn.net/chgaowei/article/details/4545211 如何使用Qt 3D开发3D场景程序: ...

  5. 2014ACM-ICPC广州站题解(摘自闭幕式)

    第39届ACM-ICPC亚洲区广州站题解 Ltysky摘抄自闭幕式题目分析 Problem A 满足px+qy=c的点(x,y)在一条直线上,而c的值由直线的截距确定,所以最大化c,就要在糖果(x,y ...

  6. 730KII 打印机 Win7 2017年11月更新系统补丁后无法打印

    卸载11月份编号为KB4048960的系统更新

  7. 在github pages网站下用jekyll制作博客教程

    https://www.jekyll.com.cn/ https://github.com/onevcat/vno-jekyll https://help.github.com/articles/us ...

  8. CharacterEncodingFilter详解

    字符编码过滤器  (Spring框架对字符编码的处理) 基于函数回调,对所有请求起作用,只在容器初始化时调用一次,依赖于servlet容器. web.xml配置文件 <filter> &l ...

  9. influxDB 1.3 中文文档

    influxDB是一个旨在处理高并发写入和查询负载的时序数据库,它是TICK框架的第二部分,influxdb用于任何包含大量时序数据应用的后台存储,包括Devops监控.应用指标数据.物联网传感器数据 ...

  10. 2018-2019-2 20175214 实验四《Android程序设计》实验报告

    实验四<Android程序设计>实验报告 一.前期准备 安装Android Studio 参考http://www.cnblogs.com/rocedu/p/6371315.html#SE ...