Codeforces 460C

比较裸的二分,但是比赛的时候脑抽,用树状数组瞎搞过了,但是边界条件没注意让hack了。

后来看到有人写了很简单的版本,又过了一遍,提醒一下自己不能忘记基本算法。

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
int a[100005],b[100005],sum[100005];
int n,m,k;
bool judge(int mid)
{
    int step=m,add=0;
    memset(sum,0,sizeof(sum));
    for(int i=0;i<n;i++)
    b[i]=a[i];
    for(int i=0;i<n;i++)
    {
        add+=sum[i];
        b[i]+=add;
        if(b[i]<mid)
        {
            int temp=mid-b[i];
            b[i]=mid;
            step-=temp;
            add+=temp;
            sum[min(i+k,n)]-=temp;
            if(step<0)
            return false;
        }
    }
    return true;
}
int main()
{
    while(cin>>n>>m>>k)
    {
        int minn=1e9;
        int maxx=0;
        for(int i=0;i<n;i++)
        {
            cin>>a[i];
            minn=min(minn,a[i]);
            maxx=max(maxx,a[i]);
        }
        int low=minn,high=m+maxx;
        int ans=minn;
        while(low<=high)
        {
            int mid=(low+high)>>1;
            if(judge(mid))
            {
                ans=max(ans,mid);
                low=mid+1;
            }
            else
            high=mid-1;
        }
        cout<<ans<<endl;
    }
}

Codeforces 460C,布布扣,bubuko.com

时间: 2024-10-22 00:11:35

Codeforces 460C的相关文章

Codeforces 460C prsent(二分答案)

//题意:给定N朵花的原先的高度,从左到右排列, //最多浇水m天,每天只能浇一次,每次使得连续的w朵花的高度增长1,问最后最矮的花的高度最高是多少. # include <stdio.h> # include <algorithm> # include <string.h> using namespace std; int main() { __int64 n,m,w,l,r,i,m1,sum; __int64 a[200010],b[200010]; while(~

codeforces 460C - Present 二分加模拟

代码有详细解释,二分模拟寻找结果,贪心选择从哪开始浇花,原则就是遇到需要浇花的就浇,至于w可以用线段树来维护线段,但也可以用一个数组标记一下,二分总是有很多问题啊,所以写很多输出用来调试,jiong /************************************************************************* > File Name: 460c.cpp > Author: yang > Mail:[email protected] > Crea

CodeForces 460C Present

题意: 输入 n,m,w, n个数,每次将三个连续的w个数+1,加m次,使得最终的序列最大,输出最大序列里的最小的数 二分+贪心(详见代码) 1 #include <iostream> 2 #include <algorithm> 3 #include <string.h> 4 using namespace std; 5 #define inf 0x3f3f3f3f 6 int a[100010],b[100010],memory[200020]; 7 int mai

Codeforces 460C 二分结果+线段树维护

发现最近碰到好多次二分结果的题目,上次多校也是,被我很机智的快速过了,这个思想确实非常不错.在正面求比较难处理的时候,二分结果再判断是否有效往往柳暗花明. 这个题目给定n个数字的序列,可以操作m次,每次要操作w个连续的数字,每次的操作将使得该段连续数字的数都+1,最后求整个序列最小值的最大值 求最小值最大,明显的二分结果的题目,我一开始还是在ACdream那个群里看到这个题,说是二分+线段树的题目,我就来做了一下..首先二分部分很容易,下界就是初始序列的最小值,上界就是 下界+m,至于怎么判断这

CodeForces 460C——二分+前缀和—— Present

Little beaver is a beginner programmer, so informatics is his favorite subject. Soon his informatics teacher is going to have a birthday and the beaver has decided to prepare a present for her. He planted n flowers in a row on his windowsill and star

cf 460C

J - Present Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 460C Appoint description:  System Crawler  (2014-11-17) Description Little beaver is a beginner programmer, so informatics is

C - Present

C - Present Time Limit:2000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 460C Description Little beaver is a beginner programmer, so informatics is his favorite subject. Soon his informatics teacher

LUXURY 7

A.Little Pony and Expected Maximum Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u Submit Status Practice CodeForces 454C Description Twilight Sparkle was playing Ludo with her friends Rainbow Dash, Apple Jack and Flutte

Codeforces Round #262 (Div. 2) 460C. Present(二分)

题目链接:http://codeforces.com/problemset/problem/460/C C. Present time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Little beaver is a beginner programmer, so informatics is his favorite subjec