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. sql视频学习关键笔记(自用记单词与学习用)

    sql字段类型 numeric(18,3)-18位整数加3位小数点(货币计量最好选这类型) sql关键字 insert. update. delete alter grant 授权. revoke 回 ...

  2. Eclipse搭建Maven项目并上传SVN备份

    本文出自:http://www.cnblogs.com/2186009311CFF/p/7226127.html 背景:近段时间在学着Java,想着用Java做BS的项目.但是项目一遇到问题又要重做, ...

  3. vue父组件更新,子组件也更新的方法

    1.父组件 使用 Math.ramdom() 2.子组件获取 然后监听这个ramdom变化,处理子组件的更新

  4. vim 复制

    要复制到别的地方,用 "+y 来复制,注意是三个字符.gg"+yG 1.复制 1)单行复制 在命令模式下,将光标移动到将要复制的行处,按“yy”进行复制: 2)多行复制 在命令模式 ...

  5. 一本通【例题4】Addition Chains——题解

    又是一道剪枝剪了半天的搜索题...题目传送 要充分利用题目中的约束条件:1.:2.对于每个k(1≤k≤m)k(1≤k≤m)满足ak=ai+aj(0≤i,j≤k−1)ak=ai+aj(0≤i,j≤k−1 ...

  6. TCP学习笔记

    TCP/IP 协议分层模型 TCP/IP 协议族按层次分别分为以下 4 层:应用层.传输层.网络层和数据链路层.层次化之后,每个层级只需要考虑自己的任务就可以了,不再需要弄清其他层级的功能了. TCP ...

  7. CG-CTF | I wanna play CTF

    这题跟bugku上的come_game超级像,于是菜狗决定研究一下,先鸣谢一下好友the fool,菜狗一直卡在开始界面哇,谢谢大佬给的第一关的数据 这是过到关卡1的数据,经过一系列的尝试得到结论: ...

  8. Oracle12c ASMM和hugepage

    在Oracle 12c,测试发现默认并不启用AMM 特性,而是使用了ASMM.因为在X86 架构下的linux 平台中,配置hugepage时,也是需要关闭AMM,使用ASMM特性. AMM分配内存的 ...

  9. DAY 6 上午

    如果不是割点,答案减少2(n-1) 如果删去割点,删去之后整个图分成多个连通块 每一个联通块的大小*其他连通块的大小之和 先求出缩点之后的树 加尽可能少的边使树变成一个边双 找出树上的所有叶子节点(度 ...

  10. 算法所产生的性能改进已经超过了硬件所带来的性能提升 The future is algorithms, not code

    w 大数据的发展,伴随的将是软件工程师的渐退,算法工程师的崛起  http://mp.weixin.qq.com/s/XTz2HnzwlgTD3g5zU2u5Tg