CF1935C.Messenger in MAC

普及+/提高

通过率:0%

时间限制:3.00s

内存限制:256MB

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

In the new messenger for the students of the Master's Assistance Center, Keftemerum, an update is planned, in which developers want to optimize the set of messages shown to the user. There are a total of nn messages. Each message is characterized by two integers aia_i and bib_i. The time spent reading the set of messages with numbers p1,p2,…,pkp_1, p_2, \ldots, p_k (1≤pi≤n1 \le p_i \le n, all pip_i are distinct) is calculated by the formula:

Largesum_i=1ka_p_i+sum_i=1k−1∣b_p_i−b_p_i+1∣\\Large \\sum\_{i=1}^{k} a\_{p\_i} + \\sum\_{i=1}^{k - 1} |b\_{p\_i} - b\_{p\_{i+1}}|

Note that the time to read a set of messages consisting of one message with number p1p_1 is equal to ap1a_{p_1}. Also, the time to read an empty set of messages is considered to be 00.

The user can determine the time ll that he is willing to spend in the messenger. The messenger must inform the user of the maximum possible size of the set of messages, the reading time of which does not exceed ll. Note that the maximum size of the set of messages can be equal to 00.

The developers of the popular messenger failed to implement this function, so they asked you to solve this problem.

在面向“大师援助中心”学生的新型即时通讯软件 Keftemerum 中,计划进行一次更新,开发者希望优化向用户展示的消息集合。一共有 nn 条消息。每条消息由两个整数 aia_i 和 bib_i 描述。阅读编号为 p1,p2,…,pkp_1, p_2, \ldots, p_k(其中 1≤pi≤n1 \le p_i \le n,且所有 pip_i 互不相同)的消息集合所需的时间,由如下公式计算:

∑i=1kapi+∑i=1k−1∣bpi−bpi+1∣\Large \sum_{i=1}^{k} a_{p_i} + \sum_{i=1}^{k - 1} |b_{p_i} - b_{p_{i+1}}|

注意:仅包含一条编号为 p1p_1 的消息的集合,其阅读时间为 ap1a_{p_1};而空消息集合的阅读时间定义为 00。

用户可自行指定其愿意在该即时通讯软件中花费的时间上限 ll。该软件需告知用户:满足阅读时间不超过 ll 的消息集合所能达到的最大可能大小。注意,该最大大小可以为 00。

这款广受欢迎的即时通讯软件的开发者未能实现此功能,因此他们请你来解决该问题。

输入格式

Each test consists of multiple test cases. The first line contains a single integer tt (1≤t≤5⋅1041 \leq t \leq 5 \cdot 10^4) — the number of test cases. The description of the test cases follows.

The first line of each test case contains two integers nn and ll (1≤n≤20001 \leq n \leq 2000, 1≤l≤1091 \leq l \leq 10^9) — the number of messages and the time the user is willing to spend in the messenger.

The ii-th of the next nn lines contains two integers aia_i and bib_i (1≤ai,bi≤1091 \le a_i, b_i \le 10^9) — characteristics of the ii-th message.

It is guaranteed that the sum of n2n^2 over all test cases does not exceed 4⋅1064 \cdot 10^6.

每个测试包含多个测试用例。第一行包含一个整数 tt(1≤t≤5⋅1041 \leq t \leq 5 \cdot 10^4),表示测试用例的数量。随后是各测试用例的描述。

每个测试用例的第一行包含两个整数 nn 和 ll(1≤n≤20001 \leq n \leq 2000,1≤l≤1091 \leq l \leq 10^9),分别表示消息数量以及用户愿意在该即时通讯软件中花费的时间。

接下来的 nn 行中,第 ii 行包含两个整数 aia_i 和 bib_i(1≤ai,bi≤1091 \le a_i, b_i \le 10^9),表示第 ii 条消息的特征。

保证所有测试用例中 n2n^2 的总和不超过 4⋅1064 \cdot 10^6。

输出格式

For each test case, output a single integer — the maximum possible size of a set of messages, the reading time of which does not exceed ll.

对于每个测试用例,输出一个整数——满足阅读时间不超过 ll 的消息集合的最大可能大小。

输入输出样例

  • 输入#1

    5
    5 8
    4 3
    1 5
    2 4
    4 3
    2 3
    1 6
    4 10
    3 12
    4 8
    2 1
    2 12
    5 26
    24 7
    8 28
    30 22
    3 8
    17 17
    5 14
    15 3
    1000000000 998244353
    179 239
    228 1337
    993 1007

    输出#1

    3
    1
    2
    1
    0

说明/提示

In the first test case, you can take a set of three messages with numbers p1=3p_1 = 3, p2=2p_2 = 2, and p3=5p_3 = 5. The time spent reading this set is equal to a3+a2+a5+∣b3−b2∣+∣b2−b5∣=2+1+2+∣4−5∣+∣5−3∣=8a_3 + a_2 + a_5 + |b_3 - b_2| + |b_2 - b_5| = 2 + 1 + 2 + |4 - 5| + |5 - 3| = 8.

In the second test case, you can take a set of one message with number p1=1p_1 = 1. The time spent reading this set is equal to a1=4a_1 = 4.

In the fifth test case, it can be shown that there is no such non-empty set of messages, the reading time of which does not exceed ll.

在第一个测试用例中,你可以选择一组三条消息,其编号分别为 p1=3p_1 = 3、p2=2p_2 = 2 和 p3=5p_3 = 5。阅读该组消息所花费的时间为 a3+a2+a5+∣b3−b2∣+∣b2−b5∣=2+1+2+∣4−5∣+∣5−3∣=8a_3 + a_2 + a_5 + |b_3 - b_2| + |b_2 - b_5| = 2 + 1 + 2 + |4 - 5| + |5 - 3| = 8。

在第二个测试用例中,你可以选择一组仅含一条消息,其编号为 p1=1p_1 = 1。阅读该组消息所花费的时间为 a1=4a_1 = 4。

在第五个测试用例中,可以证明:不存在满足条件的非空消息集合,使得其阅读时间不超过 ll。

输入解题思路,AI测评打分。不知道怎么写?

首页