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(~scanf("%I64d%I64d%I64d",&n,&m,&w))
    {
        for(i=0; i<n; i++)
            scanf("%I64d",&a[i]);
        l=0;
        r=2000000000;
        while(l<=r)
        {
            int mid=(l+r)/2;
            m1=0;
            sum=0;
            memset(b,0,sizeof(b));
            for(i=0; i<n&&m1<=m; i++)
            {
                sum=sum+b[i];
                if(sum+a[i]<mid)
                {
                    m1+=mid-(sum+a[i]);//到达mid所需的天数
                    b[i+w]-=mid-(sum+a[i]);//a[i+w]结束
                    sum=mid-a[i];
                }
            }
            if(m1<=m)
                l=mid+1;
            else
                r=mid-1;
        }
        printf("%I64d\n",l-1);
    }
    return 0;
}

Codeforces 460C prsent(二分答案)

时间: 2024-08-06 20:03:55

Codeforces 460C prsent(二分答案)的相关文章

Codeforces Round #424 (Div. 2, rated, based on VK Cup Finals) Problem D (Codeforces 831D) - 贪心 - 二分答案

There are n people and k keys on a straight line. Every person wants to get to the office which is located on the line as well. To do that, he needs to reach some point with a key, take the key and then go to the office. Once a key is taken by somebo

codeforces 460C - Present 二分加模拟

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

Codeforces 772A Voltage Keepsake - 二分答案

You have n devices that you want to use simultaneously. The i-th device uses ai units of power per second. This usage is continuous. That is, in λ seconds, the device will use λ·ai units of power. The i-th device currently has bi units of power store

Codeforces 700A As Fast As Possible(二分答案)

[题目链接] http://codeforces.com/problemset/problem/700/A [题目大意] 有一辆限载k人速度为v2的车,n个步行速度均为v1的人要通过一段长度为l的距离,每个人只能上车一次,车可以来回走,问所有人到达目的地所需要的最短时间是多少 [题解] 因为车可以载k个人,所以,我们把人k个为一组分成(n+k-1)/k组,记为p吗,设需要的最短时间为t,每个人在车上待的时间为t2,那么可以列方程v1*(t-t2)+v2*t2=l,我们可以发现t2可以用t来表示,

Codeforces Round #425 (Div. 2) Problem C (Codeforces 832C) Strange Radiation - 二分答案 - 数论

n people are standing on a coordinate axis in points with positive integer coordinates strictly less than 106. For each person we know in which direction (left or right) he is facing, and his maximum speed. You can put a bomb in some point with non-n

Codeforces Round #417 (Div. 2) C. Sagheer and Nubian Market 二分答案 +排序

Codeforces Round #417 (Div. 2) C. Sagheer and Nubian Market 二分答案 +排序 题意 有 a[ i ] 个数 要求选最多的数 使其和不超过 S ,且在此情况下,和最小选最多数情况下 和最小 且 每个数有加成 如果选了 k个数 那么加成后 就是 a[ i ] + k*i ; 题解 二分mid 表示选了个数 加成一下,将加成以后结果排序一下 , 若前 mid数 和大于 s 则此方案不可行 PS 要用 long long ..... 还有 co

Educational Codeforces Round 21 Problem F (Codeforces 808F) - 最小割 - 二分答案

Digital collectible card games have become very popular recently. So Vova decided to try one of these. Vova has n cards in his collection. Each of these cards is characterised by its power pi, magic number ci and level li. Vova wants to build a deck

Codeforces Round #256 (Div. 2)D 二分答案

D. Multiplication Table time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Bizon the Champion isn't just charming, he also is very smart. While some of us were learning the multiplication tabl

Educational Codeforces Round 3:D. Gadgets for dollars and pounds(二分答案+贪心)

看了菊苣的理解才知道怎么写..根本没思路啊一开始... 天数肯定在1~n之间,二分答案. 可以用保存前i天的最低美元和英镑汇率,没有规定哪天买,每天也没有购买数量限制,所以二分出一个答案mid的后,就在前mid天中汇率最低的时候一次性购入最便宜的就行了,judge一下总花费 打印答案的时候以ans为结果,再模拟一遍就好 #include"cstdio" #include"queue" #include"cmath" #include"s