比赛 20170919普及组 评测结果 AAAAAAAAAA
题目名称 划分数列 最终得分 100
用户昵称 Samle 运行时间 0.046 s
代码语言 C++ 内存使用 0.43 MiB
提交时间 2017-09-19 20:27:44
显示代码纯文本
#include<map>
#include<queue>
#include<cmath> 
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define R register
#define ll long long
#define inf 707406378


inline void in(ll &x) {
    static ll ch; static bool flag;
    for(flag = false,ch = getchar();ch < '0'||ch > '9';ch = getchar()) flag |= ch == '-';
    for(x = 0;isdigit(ch);ch = getchar()) x = (x<<1) + (x<<3) + ch - '0';
    x = flag ? -x : x;
}

inline void write(ll x){
    if(x<0) putchar('-'),x=-x;
    if(x>9) write(x/10);
    putchar(x%10+'0');
}


ll n,k;
ll a[100005];
ll sum,maxn;
ll l,r,mid,ans;

inline bool check(ll mid){
	R ll t=0;
	R int cnt=0;
	for(int i=1;i<=n;++i){
		t+=a[i];
		if(t<=mid && t+a[i+1]>mid)
			t=0,cnt++;
		if(cnt==k && i<n)return 1;
	}
	return 0;
}

inline int dy(){
	freopen("seqa.in","r",stdin);
	freopen("seqa.out","w",stdout);
    in(n),in(k);
	for(int i=1;i<=n;++i){
		in(a[i]);
		sum=sum+a[i];
		maxn=max(maxn,a[i]);
	}
	l=maxn,r=sum;
	while(l<=r){
		mid=(r-l)/2+l;
		if(check(mid))l=mid+1;
		else r=mid-1;
	}
	write(l);
}

int QAQ = dy();

int main(){;}