记录编号 |
380437 |
评测结果 |
AAAAAAAAAA |
题目名称 |
书的复制 |
最终得分 |
100 |
用户昵称 |
HeHe |
是否通过 |
通过 |
代码语言 |
C++ |
运行时间 |
0.003 s |
提交时间 |
2017-03-09 13:15:21 |
内存使用 |
0.32 MiB |
显示代码纯文本
//\
1204.书的复制
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<ctime>
#include<cmath>
#include<deque>
#include<queue>
#include<vector>
#include<map>//\
#include<sys/time.h>
using namespace std;
#define is_num(tmp) (tmp<='9' and tmp>='0')
inline int in(void){
char tmp(getchar());
int res(0),f(1);
while(!(is_num(tmp)||tmp=='-'))tmp=getchar();
if(tmp=='-')f=-1,tmp=getchar();
while(is_num(tmp))
res=(res<<1)+(res<<3)+(tmp^48),
tmp=getchar();
return res*f;
}//\
#define debug\
#define LOCAL
#define MAXN 600
bool check(int time);
int N,P,book[MAXN];
int sta[MAXN],end[MAXN];
int sum,ans;
int main(){
#ifdef debug
struct timeb startTime, endTime;
ftime(&startTime);
#endif
#ifndef LOCAL
freopen("books.in","r",stdin);
freopen("books.out","w",stdout);
#endif
N=in(),P=in();
for(int i=1;i<=N;++i){
sum+=book[i]=in();
}
int l(1),r(sum);
while(l<=r){
int mid=l+r>>1;
if(check(mid)){
r=mid-1;
ans=mid;
}
else{
l=mid+1;
}
}
for(int i=1;i<=P;++i){
printf("%d %d\n",sta[i],end[i]);
}
#ifdef debug
ftime(&endTime);
cout<<'\n'<<((endTime.time - startTime.time)<<10)-((endTime.time - startTime.time)<<3)-((endTime.time - startTime.time)<<4) + (endTime.millitm - startTime.millitm);
#endif
return 0;
}
bool check(int time){
int cnt=0,tmp=0;
sta[1]=1;
for(int i=1;i<=N;++i){
tmp+=book[i];
if(tmp>time){
tmp=0;
++cnt;
if(cnt>P)return 0;
end[cnt]=i-1;
sta[cnt+1]=i;
--i;
}
}
end[P]=N;
return 1;
}