# 【BZOJ】1044: [HAOI2008]木棍分割 二分+区间DP

3 2
1
1
10

10 2

## HINT

n<=50000, 0<=m<=min(n-1,1000).

1<=Li<=1000.

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
#define rep0(i,l,r) for(int i = (l);i < (r);i++)
#define rep1(i,l,r) for(int i = (l);i <= (r);i++)
#define rep_0(i,r,l) for(int i = (r);i > (l);i--)
#define rep_1(i,r,l) for(int i = (r);i >= (l);i--)
#define inf 0x7fffffff
#define pow(a) (a)*(a)
#define MS0(a) memset(a,0,sizeof(a))
typedef long long ll;
template<typename T>
{
T x=0,f=1;char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
m = x*f;
}
template<typename T>
template<typename T>
#define mod 10007
#define N 50050
int ans1,n,m;
int f[2][N],a[N],sum[N],q[N];
int check(int mx)
{
int len = 0,cnt = 0;
for(int i = 1;i <= n;i++){
len += a[i];//由于是连续捆绑的
if(len > mx) len = a[i],cnt++;// **
if(cnt > m) return 0;
if(a[i] > mx) return 0;
}
return 1;
}
void solve()
{
int l = 0,r = sum[n];
while(l <= r){
int mid = l+r>>1;
if(check(mid)) ans1 = mid,r = mid-1;
else l = mid+1;
}
}
void dp()
{
f[0][0] = 1;
int pre,cur,tot,l,r,ans2 = 0;
for(int i = 1;i <= m;i++){
pre = i&1;cur = pre^1;
tot = f[cur][0];
q[1] = 0;l = 1,r = 1;       //模拟队列;
for(int j = 1;j <= n;j++){
while(l <= r && sum[j] - sum[q[l]] > ans1) // k递增;
tot = (tot-f[cur][q[l++]]+mod)%mod;
f[pre][j] = tot;
q[++r] = j;
(tot += f[cur][j]) %= mod;
}
for(int j = n-1;j;j--){ // 最后一段合法;
if(sum[n] - sum[j] > ans1) break;
ans2 += f[pre][j];
if(ans2 >= mod) ans2 -= mod;
}
MS0(f[cur]);//原本认为没有必要重置为0，但是会WA..
}
printf("%d %d",ans1,ans2);
}
int main()
{
}