设为首页 加入收藏

TOP

Codeforces Round #262 (Div. 2) 题解(二)
2015-07-20 17:51:24 来源: 作者: 【 】 浏览:3
Tags:Codeforces Round #262 Div. 题解
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 n, m 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
传送门:点击打开链接 解题思路: 对所求解的值进行二分。ps:这里的b数组大小是n+w。 代码:
#include 
          
           
#include 
           
             #include 
            
              #include 
             
               #include 
              
                using namespace std; typedef long long lint; typedef double DB; const int MAXN = 2e5+10; const int INF = 2e9; lint a[MAXN], b[MAXN], ans; int n, m, w; bool check(lint k) { memset(b, 0, sizeof(b)); lint sum = 0, d = 0; for(int i=1; i<=n; ++i) { sum += b[i]; lint tp = k - a[i] - sum; if(tp > 0) { sum += tp; b[i+w] -= tp; d += tp; // printf("%I64d %I64d\n", tp, d); if(d > m) return false; } } return true; } int main() { scanf("%d%d%d", &n, &m, &w); for(int i=1; i<=n; ++i) scanf("%I64d", a+i); lint l = 1, r = 1ll*INF; while(l <= r) { lint mid = (l+r)>>1; if(check(mid)) l = mid + 1, ans = mid; else r = mid - 1; // printf("%I64d %I64d\n", l, r); } printf("%I64d\n", ans); return 0; }
              
             
            
           
          


首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇hdu 2147 kiki's game, 入门.. 下一篇hdu1525 Euclid's Game , 基..

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: