首页 > 其他 > 详细

CodeForces - 645 C.Enduring Exodus

时间:2019-11-30 21:36:28      阅读:67      评论:0      收藏:0      [点我收藏+]

快乐二分

用前缀和随便搞一下

#include <cstdio>
using namespace std;
const int N = 100010;
int p[N];
int n, k, cnt = 0;
inline int msum(int a, int b) {
    if (a < 0)
        a = 0;
    return (b - a - sum[b] + sum[a]);
}

inline bool judge(int s) {
    for (int i = 1; i <= n; i++) {
        if (p[i] == 1)
            continue;
        if (msum(i - s - 1, i - 1) + msum(i, i + s) >= k)
            return true;
    }
    return false;
}

int main() {
    scanf("%d %d", &n, &k);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &p[i]);
        sum[i] = sum[i - 1] + p[i];
    }
    int l = 0, r = n / 2 + 1;
    while (l < r) {
        int mid = (l + r) / 2;
        if (judge(mid))
            r = mid;
        else
            l = mid + 1;
    }
    printf("%d\n", l);
    return 0;
}

 

CodeForces - 645 C.Enduring Exodus

原文:https://www.cnblogs.com/cminus/p/11963904.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!