Codeforces Round #262 (Div. 2) 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 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 started waiting for them to grow. However, after some time the beaver noticed that the flowers stopped growing. The beaver thinks it is bad manners to present little flowers. So he decided to come up with some solutions.

There are m days left to the birthday. The height of the i-th
flower (assume that the flowers in the row are numbered from 1 to n from
left to right) is equal to ai at
the moment. At each of the remaining m days the beaver can take a special watering and water w contiguous
flowers (he can do that only once at a day). At that each watered flower grows by one height unit on that day. The beaver wants the height of the smallest flower be as large as possible in the end. What maximum height of the smallest flower can he get?

Input

The first line contains space-separated integers nm and w (1?≤?w?≤?n?≤?105; 1?≤?m?≤?105).
The second line contains space-separated integers a1,?a2,?...,?an (1?≤?ai?≤?109).

Output

Print a single integer — the maximum final height of the smallest flower.

Sample test(s)

input

6 2 3
2 2 2 2 1 1

output

2

input

2 5 1
5 8

output

9

Note

In the first sample beaver can water the last 3 flowers at the first day. On the next day he may not to water flowers at all. In the end he will get the following heights: [2, 2, 2, 3, 2, 2]. The smallest flower has height equal to 2. It‘s impossible to get
height 3 in this test.

题意分析:

二分答案,然后check一下。代码借用的别人的,自己的太丑。

代码:

#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

const int inf=1<<30;
const int maxn=2e5+100;

int n,m,w,a[maxn];
int tot[maxn];
bool check(int val)
{
    memset(tot,0,sizeof(tot));
    int now=0,res=m;
    for(int i=1;i<=n;i++)
    {
        now+=tot[i];
        if(a[i]+now<val)
        {
            res-=val-a[i]-now;
            if(res<0)
                return false;
            tot[i+w]-=val-a[i]-now;
            now+=val-a[i]-now;
        }
    }
    return true;
}
int main()
{
    while(scanf("%d%d%d",&n,&m,&w)!=EOF)
    {
        memset(tot,0,sizeof(tot));
        int l=0,r=inf;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            r=max(a[i],r);
        }
        int ans=0;
        while(l<=r)
        {
            int mid=(l+r)>>1;
            if(check(mid))
            {
                ans=mid;
                l=mid+1;
            }
            else
                r=mid-1;
        }
        printf("%d\n",ans);
    }
    return 0;
}

Codeforces Round #262 (Div. 2) C

时间: 2024-11-29 09:34:29

Codeforces Round #262 (Div. 2) C的相关文章

Codeforces Round #262 (Div. 2) 总结:二分

B. Little Dima and Equation 思路:本来前两题都很快做出来的,然后觉得ranting应该可以增加了.然后觉得代码没问题了,又想到了一组cha人的数据,然后就锁了,然后刚锁就被别人cha了看了代码才发现尼玛忘了判断小于10^9了,然后C反正想了好多种方法都不会就没心情了,就这样rating又降了 #pragma comment(linker, "/STACK:1024000000,1024000000") #include<iostream> #in

Codeforces Round #262 (Div. 2)

Codeforces Round #262 (Div. 2) A:水题,直接不断模拟即可 B:由于s(x)大小最大到1e9,所以数位和最多为81,这样只要枚举s(x),就只要枚举1到81即可,然后在计算出x,判断是否符合,符合就加进答案 C:二分高度,然后判断的时候for一遍,每次不符合的位置就去浇水,从左往右推一遍即可 D:构造,如果k >= 5, 那么就可以直接放偶数,奇数,偶数,奇数,由于偶数和偶数+1异或必然为1,所以这样放4个异或和就到最小的0了,然后k = 1,2,4都可以特判到,关

Codeforces Round #262 (Div. 2)460A. Vasya and Socks(简单数学题)

题目链接:http://codeforces.com/contest/460/problem/A A. Vasya and Socks time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya has n pairs of socks. In the morning of each day Vasya has to put o

Codeforces Round #262 (Div. 2) 460B. Little Dima and Equation(枚举)

题目链接:http://codeforces.com/problemset/problem/460/B B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Dima misbehaved during a math lesson a lot and the nas

Codeforces Round #262 (Div. 2) 题解

A. Vasya and Socks time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Vasya has n pairs of socks. In the morning of each day Vasya has to put on a pair of socks before he goes to school. When

Codeforces Round #262 (Div. 2) B

题目: B. Little Dima and Equation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Little Dima misbehaved during a math lesson a lot and the nasty teacher Mr. Pickles gave him the following pr

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

Codeforces Round #262 (Div. 2)解题报告

详见:http://robotcator.logdown.com/posts/221514-codeforces-round-262-div-2 1:A. Vasya and Socks   http://codeforces.com/contest/460/problem/A 有n双袜子,每天穿一双然后扔掉,每隔m天买一双新袜子,问最多少天后没有袜子穿.. 简单思维题:以前不注重这方面的训练,结果做了比较久,这种题自己边模拟边想.不过要多考虑trick ```c++ int main(){ i

Codeforces Round #262 (Div. 2) E. Roland and Rose 暴力

E. Roland and Rose Time Limit: 1 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/problemset/problem/460/E Description Roland loves growing flowers. He has recently grown a beautiful rose at point (0, 0) of the Cartesian coordinate system. The ro