比赛 20170919普及组 评测结果 AAAAAAAAAA
题目名称 划分数列 最终得分 100
用户昵称 KingSann 运行时间 0.061 s
代码语言 C++ 内存使用 1.08 MiB
提交时间 2017-09-19 19:59:07
显示代码纯文本
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cstdlib>

using namespace std;

#define FN "seqa"

const int N = 100010;

typedef long long ll;

int n, k;

ll a[N], ans;

bool check(ll m) {
    int blk = 0;
    ll tot = 0;
    for(int i = 1 ; i <= n ; i ++) {
        if(tot + a[i] > m) {
            blk ++;
            tot = a[i];
        } else {
            tot += a[i];
        }
    }
    if(tot) {
        blk ++;
        tot = 0;
    }
    return blk <= k;
}

int main() {
    freopen(FN ".in", "r", stdin);
    freopen(FN ".out", "w", stdout);
    scanf("%d%d", &n, &k);
    for(int i = 1 ; i <= n ; i ++) {
        scanf("%lld", &a[i]);
    }
    ll L = 0, R = 0x3f3f3f3f3f3f3f3f;
    while(L <= R) {
        ll M = (L + R) >> 1;
        if(check(M)) {
            ans = M;
            R = M - 1;
        } else {
            L = M + 1;
        }
    }
    printf("%lld\n", ans);
}