比赛 |
皇后 |
评测结果 |
AAAAAAAAAA |
题目名称 |
划分数列 |
最终得分 |
100 |
用户昵称 |
Tabing010102 |
运行时间 |
0.064 s |
代码语言 |
C++ |
内存使用 |
0.67 MiB |
提交时间 |
2017-03-19 20:55:14 |
显示代码纯文本
#include <cstdio>
using namespace std;
const int maxn = 100000+10;
const int INF = 0x7fffffff;
FILE *fin, *fout;
int n, k, d[maxn], ans;
bool check(int now) {
int num=0, cur=0;
while(num < k) {
int ori = cur;
while(d[cur+1]-d[ori] <= now) cur++;
// if(ori == cur) return false;
num++;
}
if(cur >= n) return true;
else return false;
}
int main() {
fin = fopen("seqa.in", "r");
fout = fopen("seqa.out", "w");
// fin = stdin; fout = stdout;
fscanf(fin, "%d%d", &n, &k);
for(int i = 1; i <= n; i++) {
int tmp;
fscanf(fin, "%d", &tmp);
d[i] = d[i-1]+tmp;
}
// for(int i = 1; i <= n; i++) fprintf(fout, "%d ", d[i]); fprintf(fout, "\n");
int l=0, r=INF, mid;
while(l <= r) {
mid = l+(r-l)/2;
if(check(mid)) { ans = mid; r = mid-1; }
else l = mid+1;
}
fprintf(fout, "%d\n", ans);
return 0;
}