# Lyk love painting【省选模拟赛】

## 法法！

Posted by yjjr's blog on March 1, 2018

n<=1e6 m<=100

# 分析

s1,s2分别表示第一行第二行前缀和

s3=s1+s2，即总的前缀和

# code

#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<algorithm>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define dep(i,a,b) for(int i=a;i>=b;i--)
#define ll long long
#define mem(x,num) memset(x,num,sizeof x)
#define reg(x) for(int i=last[x];i;i=e[i].next)
#define inf 0x3f3f3f
using namespace std;
{
ll f=1,x=0;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();}
return x*f;
}
const int maxn=1e5+6;
ll s1[maxn],s2[maxn],s3[maxn],l,r;
int pre1[maxn],pre2[maxn],pre3[maxn],n,m,f[maxn];
inline bool check(ll lim){
pre1[0]=0,pre2[0]=0,pre3[0]=0;
rep(i,1,n){
pre1[i]=pre1[i-1],pre2[i]=pre2[i-1],pre3[i]=pre3[i-1];
while(s1[i]-s1[pre1[i]]>lim)pre1[i]++;
while(s2[i]-s2[pre2[i]]>lim)pre2[i]++;
while(s3[i]-s3[pre3[i]]>lim)pre3[i]++;
}
mem(f,inf);f[0]=0;
rep(i,1,n){
f[i]=min(f[i],f[pre3[i]]+1);
int findpre1=i,findpre2=i,s=0;
while(s<m&&(findpre1||findpre2)){
if(findpre1>findpre2)findpre1=pre1[findpre1];else findpre2=pre2[findpre2];
s++;
f[i]=min(f[i],f[max(findpre1,findpre2)]+s);
}
if(f[i]>m)return 0;
}
return 1;
}
int main()
{