枚举 c <script type="math/tex" id="MathJax-Element-229">c</script>,动态分块维护各块答案。再维护最大值即可。(注意单调性)
#include <bits/stdc++.h>
#define gc getchar()
#define ll long long
#define N 100009
#define M 1009
using namespace std;
ll n,w,limit,Max_p,Max[M],pos[M],belong[N],Ans,Pos;
ll f[N],p[M],k[M];//f[i]:add of ansi p[i]:add of i-th block
struct node
{
ll a,b;
bool operator <(const node &rhs) const
{
return b<rhs.b;
}
}P[N];
ll read()
{
ll x=1;
char ch;
while (ch=gc,ch<'0'||ch>'9') if (ch=='-') x=-1;
ll s=ch-'0';
while (ch=gc,ch>='0'&&ch<='9') s=s*10+ch-'0';
return s*x;
}
void ins(ll x)
{
for (ll i=x;belong[i]==belong[x];i--)
{
f[i]++;
ll now_ans=i*(f[i]+p[belong[x]]);
if (now_ans>Max[belong[x]])
Max[belong[x]]=now_ans,pos[belong[x]]=i;
}
k[belong[x]]=N*M;
for (ll i=pos[belong[x]]+1;belong[i]==belong[x];i++)
k[belong[x]]=min(k[belong[x]],(Max[belong[x]]-i*(f[i]+p[belong[x]]))/(i-pos[belong[x]]));
for (ll i=1;i<belong[x];i++)
{
p[i]++,Max[i]+=pos[i];
k[i]--;
if (k[i]<=0)
{
for (ll j=pos[i]+1;belong[j]==i;j++)
{
ll now_ans=j*(f[j]+p[i]);
if (now_ans>Max[i])
Max[i]=now_ans,pos[i]=j;
}
k[i]=N*M;
for (ll j=pos[i]+1;belong[j]==i;j++)
k[i]=min(k[i],(Max[i]-j*(f[j]+p[i]))/(j-pos[i]));
}
}
}
int main()
{
n=read(),w=read();
for (ll i=1;i<=n;i++)
{
P[i].a=read(),P[i].b=read();
Max_p=max(Max_p,P[i].a);
}
sort(P+1,P+n+1);
limit=(int)sqrt(Max_p);
for (ll i=1;i<=Max_p;i++)
belong[i]=i/limit+1;
for (ll i=1;i<=belong[Max_p];i++)
pos[i]=(i-1)*limit;
ll now=1;
for (ll c=0;c<=P[n].b+1;c++)
{
while (P[now].b<c&&now<=n) ins(P[now].a),now++;
Ans=0,Pos=1;
for (ll i=1;i<=belong[Max_p];i++)
if (Ans<Max[i]) Ans=Max[i],Pos=pos[i];
printf("%lld %lld\n",Ans+(n-now+1)*w*c,Pos);
}
return 0;
}