A11286 | Messenger in MAC
时间限制1s
内存限制256MB
通过 / 提交0/0
题目描述
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 $n$ messages. Each message is characterized by two integers $a_i$ and $b_i$ . The time spent reading the set of messages with numbers $p_1, p_2, \ldots, p_k$ ( $1 \le p_i \le n$ , all $p_i$ are distinct) is calculated by the formula:
$$$$\Large \sum_{i=1}^{k} a_{p_i} + \sum_{i=1}^{k - 1} |b_{p_i} - b_{p_{i+1}}| $$ </p><p>Note that the time to read a set of messages consisting of <span class="tex-font-style-bf">one</span> message with number $p\_1$ is equal to $a\_{p\_1}$ . Also, the time to read an empty set of messages is considered to be $0$ .</p><p>The user can determine the time $l$ 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 $l$ . Note that the maximum size of the set of messages can be equal to $0$$$.
The developers of the popular messenger failed to implement this function, so they asked you to solve this problem.
$$$$\Large \sum_{i=1}^{k} a_{p_i} + \sum_{i=1}^{k - 1} |b_{p_i} - b_{p_{i+1}}| $$ </p><p>Note that the time to read a set of messages consisting of <span class="tex-font-style-bf">one</span> message with number $p\_1$ is equal to $a\_{p\_1}$ . Also, the time to read an empty set of messages is considered to be $0$ .</p><p>The user can determine the time $l$ 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 $l$ . Note that the maximum size of the set of messages can be equal to $0$$$.
The developers of the popular messenger failed to implement this function, so they asked you to solve this problem.
输入格式
Each test consists of multiple test cases. The first line contains a single integer $t$ ( $1 \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 $n$ and $l$ ( $1 \leq n \leq 2000$ , $1 \leq l \leq 10^9$ ) — the number of messages and the time the user is willing to spend in the messenger.
The $i$ -th of the next $n$ lines contains two integers $a_i$ and $b_i$ ( $1 \le a_i, b_i \le 10^9$ ) — characteristics of the $i$ -th message.
It is guaranteed that the sum of $n^2$ over all test cases does not exceed $4 \cdot 10^6$ .
The first line of each test case contains two integers $n$ and $l$ ( $1 \leq n \leq 2000$ , $1 \leq l \leq 10^9$ ) — the number of messages and the time the user is willing to spend in the messenger.
The $i$ -th of the next $n$ lines contains two integers $a_i$ and $b_i$ ( $1 \le a_i, b_i \le 10^9$ ) — characteristics of the $i$ -th message.
It is guaranteed that the sum of $n^2$ over all test cases does not exceed $4 \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 $l$ .
输入输出样例
输入 #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 $p_1 = 3$ , $p_2 = 2$ , and $p_3 = 5$ . The time spent reading this set is equal to $a_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 $p_1 = 1$ . The time spent reading this set is equal to $a_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 $l$ .
In the second test case, you can take a set of one message with number $p_1 = 1$ . The time spent reading this set is equal to $a_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 $l$ .
C++ 编辑器
输入
输出
可保存默认模板;新题优先使用已保存模板。
当前快捷键仅展示,暂不支持修改。
- 撤销
Ctrl / ⌘ + Z - 重做
Ctrl / ⌘ + Y - 查找
Ctrl / ⌘ + F - 全选
Ctrl / ⌘ + A - 复制
Ctrl / ⌘ + C - 剪切
Ctrl / ⌘ + X - 粘贴
Ctrl / ⌘ + V - 自动排版
工具栏排版按钮 - 草稿保存
编辑时自动保存到本机
历史
提交记录
状态说明时间源码
AI
作答助手
你好,我是作答助手。可以问思路、复杂度、样例含义或代码报错原因;不会直接给出完整 AC 代码。
确定要清空代码吗?
提交通过
评测结果:Accepted