BTW wants to buy a gift for her BF and plans to buy an integer array. Generally Integer arrays are costly and hence bought the cheapest one from the market. Her BF is very judgemental and assess the quality of the array by just looking at the smallest element in the array. Hence, she decided to improve the quality of the array. Increment operation on array elements are very costly and would take ONE FULL DAY to complete. Also, Increment operations can be done in parallel on at most M consecutive array elements. She only has K days left. Help BTW calculate the maximum possible “quality” of the array she can attain.

(BTW BTW is the name of the character :P )

Input

Very first line contains T – (number of test cases)

First line in each test case contains N – (size of the array BTW has bought from the market), M, K (days left)

Second line in each test case contains N integers (values of the initial array BTW bought from the market)

Output

Print the maximum possible “quality” she can attain.

Constraints

1<=T<=100

1<=N<=10^5

0<=M<=N

0<=K<=10^9

0<=Values of array<=10^9

Example

Sample test case 1

Input

3 2 1

2 2 3

Output

3

Sample test case 2

Input

3 2 1

2 3 2

Output

2

题意:有N个物品,排成一排,给个物品有一个价值,给定M,K,表示有K次机会,每次将一段连续的不超过M长度的区间的物品价值都加1。求将最小价值最大化是。

思路:开始一看100组数据,二分复杂度是(T*N*log(Min+K))。。。以为过不了,想其他方法又想不出,二分试一试居然过了。。。
           给长度为M的区间都加一个值的操作是:delta数据记录累加前缀和,如果位置i加值val,那么位置i+M减值val,然后就可以二分乱搞了。
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=;
const int inf=;
ll sum[maxn],tsum[maxn],delta[maxn],N,M,K;
bool check(ll Mid){
ll tmp=K;
for(int i=;i<=N;i++) tsum[i]=sum[i],delta[i]=;
for(int i=;i<=N;i++){
delta[i]+=delta[i-];
if(tsum[i]+delta[i]<Mid&&tmp){
ll t=min(tmp,Mid-tsum[i]-delta[i]);
delta[i]+=t;
if(M+i<=N) delta[M+i]-=t;
tmp-=t;
}
tsum[i]+=delta[i];
if(tsum[i]<Mid) return false;
}
return true;
}
int main()
{
int T,i,j;
ll Min;
scanf("%d",&T);
while(T--){
scanf("%lld%lld%lld",&N,&M,&K); Min=inf;
for(i=;i<=N;i++){
scanf("%lld",&sum[i]);
if(sum[i]<Min) Min=sum[i];
}
ll L=Min,R=Min+K,Mid,ans=Min;
while(L<=R){
Mid=(L+R)>>1LL;
if(check(Mid)) ans=Mid,L=Mid+;
else R=Mid-;
}
printf("%lld\n",ans);
}
return ;
}

SPOJ:Help BTW(二分)的更多相关文章

  1. SPOJ PHT【二分】+SPOJ INUM【最小/大值重复】

    BC 两道其实都是水 没有完整地想好直接就码出事情.wa了一次以后要找bug,找完要把思路理的非常清楚 SPOJ PHT[二分] #include<bits/stdc++.h> using ...

  2. BZOJ 2780: [Spoj]8093 Sevenk Love Oimaster( 后缀数组 + 二分 + RMQ + 树状数组 )

    全部串起来做SA, 在按字典序排序的后缀中, 包含每个询问串必定是1段连续的区间, 对每个询问串s二分+RMQ求出包含s的区间. 然后就是求区间的不同的数的个数(经典问题), sort queries ...

  3. SPOJ 220 Relevant Phrases of Annihilation(后缀数组+二分答案)

    [题目链接] http://www.spoj.pl/problems/PHRASES/ [题目大意] 求在每个字符串中出现至少两次的最长的子串 [题解] 注意到这么几个关键点:最长,至少两次,每个字符 ...

  4. SPOJ COMPANYS Two Famous Companies 最小生成树,二分,思路 难度:2

    http://www.spoj.com/problems/COMPANYS/en/ 题目要求恰好有k条0类边的最小生成树 每次给0类边的权值加或减某个值delta,直到最小生成树上恰好有k条边为0,此 ...

  5. spoj 287 NETADMIN - Smart Network Administrator【二分+最大流】

    在spoj上用题号找题就已经是手动二分了吧 把1作为汇点,k个要入网的向t连流量为1的边,因为最小颜色数等于最大边流量,所以对于题目所给出的边(u,v),连接(u,v,c),二分一个流量c,根据最大流 ...

  6. SPOJ MINSUB - Largest Submatrix(二分+单调栈)

    http://www.spoj.com/problems/MINSUB/en/ 题意:给出一个n*m的矩阵M,和一个面积k,要使得M的子矩阵M'的最小元素最大并且面积大于等于k,问子矩阵M'的最小元素 ...

  7. SPOJ AMR10E Stocks Prediction --二分求和+矩阵快速幂

    题意:给一个递推式S(n) = a1*S(n-1)+...+aR*S(n-R),要求S(k)+S(2k)+...+S(nk)的值. 分析:看到n的大小和递推式,容易想到矩阵快速幂.但是如何转化呢? 首 ...

  8. SPOJ AMR12A The Black Riders --二分+二分图最大匹配

    题意:有n个人,m个洞.每个洞能容纳一个人,每个人到每个洞需要花费一些时间.每个人到达一个洞后可以花C的时间来挖一个洞,并且最多挖一个洞,这样又能多容纳一人.求能使至少K个人进洞的最短时间. 解法:看 ...

  9. SPOJ TEMPLEQ - Temple Queues(二分查找+树状数组)

    题意: 有N个队伍(1 <= N <= 100,000),每个队伍开始有ai个人[0 <= ai<= 100,000,000],有Q个操作[0<=Q<= 500,0 ...

随机推荐

  1. ZOJ 3717 二分+2-sat判定。

    好久没有2-sat了,此题当复习之用,二分求最大值+2-sat判断可行,此题主要跪于题意:The results should be rounded to three decimal places. ...

  2. eslint 在webstorm配置

    1.安装nodejs和eslint 2.在 webstorm 的 file - setting搜索eslint,配置eslint路径 3.在项目目录下新建.eslintrc文件 4.配置eslint ...

  3. Oracle 12c安装报错Installation failed to access the temporary location(无法访问临时位置)

    报错如图 1.先检查当前windows账户用户名是否为全英文,没有就新建一个,大多数用户败在这一步,而官方也没有解释 如何新建:开始-->控制面板-->用户账户和家庭安全-->用户账 ...

  4. spark学习(六)Java版RDD基本的基本操作

    1.map算子 private static void map() { //创建SparkConf SparkConf conf = new SparkConf() .setAppName(" ...

  5. Mysql 性能优化20个原则(2)

    5. 在Join表的时候使用相当类型的例,并将其索引 如果你的应用程序有很多 JOIN 查询,你应该确认两个表中Join的字段是被建过索引的.这样,MySQL内部会启动为你优化Join的SQL语句的机 ...

  6. js可以控制文件上传的速度吗?

    为了减轻服务器负载,对于上传和下载的情况,我们需要进行流量控制,一般的方法是服务端做限流举措,比如很多ftp服务器,但是我想是不是可以使用前端js做呢? 顺着这个想法,我查了下资料,目前来看结论是No ...

  7. (CF)Codeforces445A DZY Loves Chessboard(纯实现题)

    转载请注明出处:http://blog.csdn.net/u012860063? viewmode=contents 题目链接:http://codeforces.com/problemset/pro ...

  8. HeatMap(热图)的原理和实现

    先来看两张图: (1)10年世界杯决赛,冠军西班牙队中门将.后卫.中场及前锋的跑位热图 通过热图,我们可以很清楚的看出四个球员在比赛中跑动位置的差异. (2)历史地震震源位置的热图 也可以很清楚的看出 ...

  9. 转:libev和libevent的设计差异

    转:http://www.cnblogs.com/Lifehacker/p/whats_the_difference_between_libevent_and_libev_chinese.html [ ...

  10. hdu 1710 Binary Tree Traversals 前序遍历和中序推后序

    题链;http://acm.hdu.edu.cn/showproblem.php?pid=1710 Binary Tree Traversals Time Limit: 1000/1000 MS (J ...