#abc327f. F - Apples

F - Apples

Score : 550550 points

问题描述

在数轴上排列着苹果树,共有 NN 个苹果从树上落下。具体来说,对于每个 1iN1\leq i\leq N,第 ii 个苹果在时刻 TiT_i 落在坐标点 XiX_i

高桥有一个篮子,其耐久度为 DD,长度为 WW,他可以精确地执行一次以下操作:

选择正整数 SSLL。他在时刻 S0.5S-0.5 将篮子设置在范围 L0.5xL+W0.5L-0.5\leq x\leq L+W-0.5 内,并在时刻 S+D0.5S+D-0.5 收回篮子。在这段时间内,篮子覆盖范围内落下的所有苹果都会被他收集到。

一旦篮子被设置好后就不能移动,而且一旦收回篮子后就不能再次设置。
请找出高桥最多可以获得的苹果数量。

以上为通义千问 qwen-max 翻译,仅供参考。

Problem Statement

There are apple trees lined up on a number line, and NN apples fall from the trees.
Specifically, for each 1iN1\leq i\leq N, an apple falls at coordinate XiX_i at time TiT_i.

Takahashi has a basket with durability DD and length WW, and he can take the following action exactly once.

Choose positive integers SS and LL. He sets up the basket to cover the range L0.5xL+W0.5L-0.5\leq x\leq L+W-0.5 at time S0.5S-0.5, and retrieves it at time S+D0.5S+D-0.5. He gets all the apples that fell into the range covered by the basket between the time it was set up and the time it was retrieved.

He cannot move the basket once it has been set up, nor can he set it up again once it has been retrieved.
Find the maximum number of apples that he can get.

Constraints

  • 1N2×1051 \leq N\leq 2\times 10^5
  • 1D2×1051 \leq D\leq 2\times 10^5
  • 1W2×1051 \leq W\leq 2\times 10^5
  • 1Ti2×1051 \leq T_i\leq 2\times 10^5
  • 1Xi2×1051 \leq X_i\leq 2\times 10^5
  • All pairs (Ti,Xi)(T_i,X_i) are different.
  • All input values are integers.

Input

The input is given from Standard Input in the following format:

NN DD WW

T1T_1 X1X_1

T2T_2 X2X_2

\vdots

TNT_N XNX_N

Output

Print the maximum number of apples that Takahashi can get.

Sample Input 1

8 4 3
1 1
3 4
6 4
5 2
4 2
4 3
5 5
7 3

Sample Output 1

5

If Takahashi chooses S=3S=3 and L=2L=2, he will set up the basket to cover the range 1.5x4.51.5\leq x\leq 4.5 from time 2.52.5 to 6.56.5. Then, he gets the following five apples:

  • The apple that falls at coordinate X2=4X_2=4 at time T2=3T_2=3
  • The apple that falls at coordinate X3=4X_3=4 at time T3=6T_3=6
  • The apple that falls at coordinate X4=2X_4=2 at time T4=5T_4=5
  • The apple that falls at coordinate X5=2X_5=2 at time T5=4T_5=4
  • The apple that falls at coordinate X6=3X_6=3 at time T6=4T_6=4

There is no way to get six or more apples, so print 55.

update @ 2024/3/10 01:51:45