记录编号 |
452684 |
评测结果 |
AAAAAAAAAA |
题目名称 |
划分数列 |
最终得分 |
100 |
用户昵称 |
Samle |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.038 s |
提交时间 |
2017-09-20 07:30:56 |
内存使用 |
0.43 MiB |
显示代码纯文本
#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(){;}