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
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

2010 ACM-ICPC Multi-University Training Contest(5)——Host by BJTU


Recommend

zhengfeng

/*
一道一道有毒的题,忘了一种竟然可以n个线段
*/
#include<bits/stdc++.h>
using namespace std;
int d[200100][20];
int n,k,cur,ob,maxn;
void init()
{
    for (int j = 1; (1 << j) < n; j++){
        int t = (1 << j) - 1;
        for (int i = 0; i+t < n; i++){
            d[i][j] = max(d[i][j-1], d[i+(1<<(j-1))][j-1]);
        }
    }
}
inline int RMQ(int a, int b)
{
    int l = int(log(double(b-a+1))/log(2.0));
    return max(d[a][l], d[b+1-(1<<l)][l]);
}
int main()
{
    //freopen("C:\\Users\\acer\\Desktop\\in.txt","r",stdin);
    while(scanf("%d%d",&n,&k)&&n>=0&&k>=0)
    {
        ob=0;
        maxn=0;
        for(int i=0;i<n;i++)
        {
            scanf("%d",&d[i][0]);
            ob+=d[i][0];
            maxn=max(maxn,d[i][0]);
        }
        if(ob<=k)
        {
            puts("-1");
            continue;
        }
        init();//RMQ预处理
        /*二分找最小值*/
        int ans=n;
        for(int m=max(1,k/maxn);m<n;m++)
        {
            cur=0;
            int t=n/m;//分组的长度
            //cout<<"t="<<t<<endl;
            for(int i=1;i<=m;i++)//枚举的组数
            {
                cur+=RMQ(t*(i-1),t*i-1);
                //cout<<t*(i-1)+1<<" "<<t*i<<endl;
                if(cur>k)
                    break;
            }
            if(cur>k)
            {
                ans=m;
                break;
            }
        }
        printf("%d\n",ans);
    }
    return 0;
}
时间: 2024-10-12 08:34:46

Interviewe的相关文章

Interviewe(hdu3486)

Interviewe Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 6689    Accepted Submission(s): 1582 Problem Description YaoYao has a company and he wants to employ m people recently. Since his compa

HDOJ 3486 Interviewe ST RMQ

http://acm.hdu.edu.cn/showproblem.php?pid=3486题意:n个人,有顺序,每个人有自己的能力值.你要从中选m个,分成每段长度[n/m]的小段,如果不能整除,多余的最后那段舍弃.每个小段取能力值最大的那个人.所取的人的能力值之和要大于k,问最少的m是多少. 分析:考虑种种做法,均不可行,然后绕回rmq上.n有20w,虽然st可以o(nlogn)预处理o(1)查询,但是如果枚举m,那么每次查询是m次,最坏可是o(n^2)的复杂度.只好无奈看题解了,结果正解就是

题单二:图论500

http://wenku.baidu.com/link?url=gETLFsWcgddEDRZ334EJOS7qCTab94qw5cor8Es0LINVaGMSgc9nIV-utRIDh--2UwRLvsvJ5tXFjbdpzbjygEdpGehim1i5BfzYgYWxJmu ==========  以下是最小生成树+并查集=========================[HDU]1213         How Many Tables        基础并查集★1272         小

图论五百题!

生死看淡不服就淦,这才是人生! =============================以下是最小生成树+并查集======================================[HDU]1213 How Many Tables 基础并查集★1272 小希的迷宫 基础并查集★1325&&poj1308 Is It A Tree? 基础并查集★1856 More is better 基础并查集★1102 Constructing Roads 基础最小生成树★1232 畅通工程 基

图论 500题——主要为hdu/poj/zoj

转自——http://blog.csdn.net/qwe20060514/article/details/8112550 =============================以下是最小生成树+并查集======================================[HDU]1213   How Many Tables   基础并查集★1272   小希的迷宫   基础并查集★1325&&poj1308  Is It A Tree?   基础并查集★1856   More i

图论精炼500题

忘了从哪转的了... =============================以下是最小生成树+并查集====================================== [HDU] 1213               How Many Tables                    基础并查集★ 1272               小希的迷宫                     基础并查集★ 1325&&poj1308    Is It A Tree?       

hdu图论题目分类

=============================以下是最小生成树+并查集====================================== [HDU] 1213 How Many Tables 基础并查集★ 1272 小希的迷宫 基础并查集★ 1325&&poj1308 Is It A Tree? 基础并查集★ 1856 More is better 基础并查集★ 1102 Constructing Roads 基础最小生成树★ 1232 畅通工程 基础并查集★ 123

学习 LCA&amp;&amp;RMQ

参考:点击打开链接 点击打开链接      点击打开链接(一些总结) 点击打开链接(不错的模板) 题目:点击打开链接 花了4天时间做完了这个专题,LCA的问题用处还是很大,同时能体会RMQ的ST算法中dp的味道.基本方法就是ST,LCA转RMQ,LCA的Tarjan,LCA倍增(这个可存储边权) 这个专题后面四道题都非常好,推荐大家做做. 细节: 1. ST方法2^i 包含自己,因此其真实只包含到i+2^k-1的范围. 2. Tarjan一般都很快,但不适合修改类型的问题,关于权值长度之类的,S

LCA和RMQ题目汇总

1.HDU 3183 <span style="color:#000099;">A Magic Lamp Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 1624    Accepted Submission(s): 628 Problem Description Kiki likes traveling. One