Codeforces 460C Present 二分+前缀和
来源:互联网 发布:初级程序员考试大纲 编辑:程序博客网 时间:2024/06/04 23:37
点击打开链接
题意:n个数,m次操作 n,m<=1e5,操作:每次将[i,i+w)中的数+1,问m次操作后最小值最大为?
二分最值x,判定:res为a[i]过去被累加次数,显然res=[a[i-w+1]~a[i-1]]被累加的次数之和,利用前缀和b[i]记录前i个数累加之和即可求出res
若a[i]+res<x 则a[i]肯定要操作,更新次数即可.
#include <bits/stdc++.h>using namespace std;typedef long long ll;const int N=2e5+20;ll n,m,w,a[N];ll b[N];//前i个数总共被加多少次 bool check(ll x){ll cnt=0;memset(b,0,sizeof(b));for(ll i=1;i<=n;i++){ll res=0; b[i]=b[i-1];//ll k=max((ll)0,i-w);//res=b[i-1]-b[k];//a[i]过去被加了多少次? [i-w+1~i-1]加了多少次 if(a[i]+res<x)b[i]+=x-(a[i]+res);}return b[n]<=m;}int main(){while(cin>>n>>m>>w){for(int i=1;i<=n;i++)scanf("%I64d",&a[i]);ll l=1,r=2e10,ans;while(l<=r){ll mid=(l+r)>>1;if(check(mid)){ans=mid;l=mid+1;}elser=mid-1;}cout<<ans<<endl;}return 0;}
0 0
- Codeforces 460C Present 二分+前缀和
- Codeforces 460C Present(二分)
- Codeforces 460C Present 二分答案
- CodeForces 460C--- Present(二分+贪心)
- codeforces 460C - Present 二分加模拟
- Codeforces 460C Present (贪心 + 二分)
- Codeforces 460C Present【二分+思维优化】
- 【二分】460C Present
- Codeforces 460C —— Present(二分答案)
- Codeforces Round #262 (Div. 2) 460C. Present(二分)
- Present - CODEFORCES, 460c 二分 扫描线求和
- codeforces 460 C Present 二分+贪心 最大化最小值问题
- *codeforces 460C Present
- CodeForces - 460C Present
- Codeforces 460C Present
- Codeforces 460C Present
- Codeforces 460C Present
- codeforces 776C Molly's Chemicals(前缀和 二分搜索)
- 【leetCode523】Continuous Subarry Sum
- 传递指针和传递指针的指针
- Android在thread中Toast不能显示有关问题解决
- dpdk makefile 创建自己的实例程序
- elastic-job动态添加定时任务
- Codeforces 460C Present 二分+前缀和
- detected problems with app native libraries
- 十六进制字符串转中文
- mvn库强制更新
- 控件的拖曳
- laravel5.1自定义常量的配置和使用
- 如何居中正常元素、浮动元素以及绝对定位元素
- Error:Error converting bytecode to dex:
- Linux I2C core