• CF 551C 二分 1e5


     1 #include<bits/stdc++.h>
     2 #define ll long long
     3 using namespace std;
     4 const ll INF = 1e18;
     5 const int N = 1e5 + 10;
     6 int n, m, t;
     7 ll a[N], b[N];
     8 
     9 ll MAX(ll a, ll b)
    10 {
    11     return a > b ? a : b;
    12 }
    13 /*
    14 bool check(ll t)
    15 {
    16     ll now = n;
    17     for(int i = 1 ; i <= n ; i++){
    18         b[i] = a[i];
    19     }
    20     for(int i = 1 ; i <= m && now; i++){
    21         ll tmp = t - now;
    22         if(tmp < 0)    break;//当前点无法到达 
    23         while(now >= 1 && b[now] <= t){
    24             t -= b[now];
    25             now--;
    26         }
    27     }
    28     if(now < 1)    return true;
    29     return false;
    30 }*/
    31 
    32 bool check(ll mid)
    33 {
    34     ll cnt = m - 1, s = 0;
    35     for(ll i = 1 ; i <= t ; i++){
    36         s += a[i];
    37         while(s + i > mid){
    38             cnt--;
    39             s -= mid - i;
    40             if(cnt < 0)    return false;
    41         }
    42     }
    43     return true;
    44 }
    45 
    46 int main(){
    47     scanf("%d %d",&n,&m);
    48     for(int i = 1 ; i <= n ; i++){
    49         scanf("%lld",&a[i]);
    50         if(a[i])    t = i;
    51     }
    52     ll l = 1, r = INF, mid;
    53     while(l < r){
    54         mid = (l + r) >> 1;
    55         if(check(mid)){
    56             r = mid;
    57         }else{
    58             l = mid + 1;
    59         }
    60     }
    61     printf("%lld
    ",l);
    62     
    63     
    64     return 0;
    65 }

    hole 留个坑

  • 相关阅读:
    常见的兼容问题
    css3新增伪类
    完美的js运动框架
    C++ 常用宏
    多线程代码段 自清理线程
    寒假自学(十一)
    寒假自学(十)
    寒假自学(九)
    寒假自学(八)
    寒假自学(七)
  • 原文地址:https://www.cnblogs.com/ecustlegendn324/p/13961447.html
Copyright © 2020-2023  润新知