SPOJ:Help BTW(二分)
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。求将最小价值最大化是。
#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(二分)的更多相关文章
- SPOJ PHT【二分】+SPOJ INUM【最小/大值重复】
BC 两道其实都是水 没有完整地想好直接就码出事情.wa了一次以后要找bug,找完要把思路理的非常清楚 SPOJ PHT[二分] #include<bits/stdc++.h> using ...
- BZOJ 2780: [Spoj]8093 Sevenk Love Oimaster( 后缀数组 + 二分 + RMQ + 树状数组 )
全部串起来做SA, 在按字典序排序的后缀中, 包含每个询问串必定是1段连续的区间, 对每个询问串s二分+RMQ求出包含s的区间. 然后就是求区间的不同的数的个数(经典问题), sort queries ...
- SPOJ 220 Relevant Phrases of Annihilation(后缀数组+二分答案)
[题目链接] http://www.spoj.pl/problems/PHRASES/ [题目大意] 求在每个字符串中出现至少两次的最长的子串 [题解] 注意到这么几个关键点:最长,至少两次,每个字符 ...
- SPOJ COMPANYS Two Famous Companies 最小生成树,二分,思路 难度:2
http://www.spoj.com/problems/COMPANYS/en/ 题目要求恰好有k条0类边的最小生成树 每次给0类边的权值加或减某个值delta,直到最小生成树上恰好有k条边为0,此 ...
- spoj 287 NETADMIN - Smart Network Administrator【二分+最大流】
在spoj上用题号找题就已经是手动二分了吧 把1作为汇点,k个要入网的向t连流量为1的边,因为最小颜色数等于最大边流量,所以对于题目所给出的边(u,v),连接(u,v,c),二分一个流量c,根据最大流 ...
- SPOJ MINSUB - Largest Submatrix(二分+单调栈)
http://www.spoj.com/problems/MINSUB/en/ 题意:给出一个n*m的矩阵M,和一个面积k,要使得M的子矩阵M'的最小元素最大并且面积大于等于k,问子矩阵M'的最小元素 ...
- SPOJ AMR10E Stocks Prediction --二分求和+矩阵快速幂
题意:给一个递推式S(n) = a1*S(n-1)+...+aR*S(n-R),要求S(k)+S(2k)+...+S(nk)的值. 分析:看到n的大小和递推式,容易想到矩阵快速幂.但是如何转化呢? 首 ...
- SPOJ AMR12A The Black Riders --二分+二分图最大匹配
题意:有n个人,m个洞.每个洞能容纳一个人,每个人到每个洞需要花费一些时间.每个人到达一个洞后可以花C的时间来挖一个洞,并且最多挖一个洞,这样又能多容纳一人.求能使至少K个人进洞的最短时间. 解法:看 ...
- SPOJ TEMPLEQ - Temple Queues(二分查找+树状数组)
题意: 有N个队伍(1 <= N <= 100,000),每个队伍开始有ai个人[0 <= ai<= 100,000,000],有Q个操作[0<=Q<= 500,0 ...
随机推荐
- 2017 ACM/ICPC Asia Regional Urumuqi Online 记录
比赛题目链接 Urumuqi
- PAT (Advanced Level) 1086. Tree Traversals Again (25)
入栈顺序为先序遍历,出栈顺序为中序遍历. #include<cstdio> #include<cstring> #include<cmath> #include&l ...
- hadoop+yarn+hbase+storm+kafka+spark+zookeeper)高可用集群详细配置
配置 hadoop+yarn+hbase+storm+kafka+spark+zookeeper 高可用集群,同时安装相关组建:JDK,MySQL,Hive,Flume 文章目录 环境介绍 节点介绍 ...
- jQuery学习总结(一)——jQuery基础与学习资源
前一段时间录了一套关于jQuery的视频分享给大家,可以在下载区下载到,本来想配合文字一起的,后面发现视频+帮助文档也是非常好的学习方法. 一.jQuery简介与第一个jQuery程序 1.1.jQu ...
- scp、paramiko、rsync上传下载限流、限速、速度控制方法
1.scp限速 scp -l 800 a.txt user@ip:/home/admin/downloads 此时的传输速率就是800/8=100KB左右 man -a scp查看参数含义.注意单 ...
- Web常见安全漏洞原理及防范-学习笔记
公司在i春秋上面报的一个课程.http://www.ichunqiu.com/course/55885,视频学习. OWASP (Open Web Application Secutiry Proje ...
- Python 基础教程之包和类的用法
Python 基础教程之包和类的用法 建立一个文件夹filePackage 在filePackage 文件夹内创建 __init__.py 有了 __init__.py ,filePackage才算是 ...
- BUPT复试专题—寻找第 K 小的数(2009)
题目描述 给你 n 个完全不相同整数(n<=300),每一个数都大于 0 并且小于 1000,请找出 第 k 小的数. 输入 输入包括两行,第一行用空格隔开的两个数 n 和 k;第二行有 n 个 ...
- 子组件跟随父组件re-render
想象一下这种场景,一个父组件下面一大堆子组件.然后呢,这个父组件re-render.是不是下面的子组件都得跟着re-render.可是很多子组件里面是冤枉的啊!!很多子组件的props 和 state ...
- Autolayout和VFL
Autolayout,開始于iOS6.0 一.什么时候用autolayout比較适合 1.不负责任的骑墙派说法:apple的设备越来越多了,你的应用应该都使用al. (而且用sb) 2.要 ...