QOJ.ac

QOJ

시간 제한: 2.5 s 메모리 제한: 256 MB 총점: 100

#14299. 反应

통계

Nicky 正在进行关于化学反应活性的实验。他准备了 $N$ 个实验,索引为 $0$ 到 $N - 1$。现在他需要选择他的起始实验,然后他将按顺序进行所有索引大于或等于所选实验索引的实验。换句话说,如果他决定从索引为 $S$ 的实验开始,他将依次进行实验 $S, S + 1, \dots, N - 1$。

在开始实验之前,他有一个装有溶液的容器。溶液的初始温度为 $0$ 度。在第 $i$ 个实验($0 \le i \le N - 1$)期间,他按顺序执行以下两个步骤:

  1. 将溶液的温度改变给定的整数度数(可以增加或减少任意量,或者保持不变);
  2. 进行实验并检查是否发生反应。

已知对于第 $i$ 个实验,温度会改变 $D_i$ 度——如果 $D_i > 0$ 则温度升高,如果 $D_i < 0$ 则温度降低,如果 $D_i = 0$ 则保持不变。此外,只有当当前温度(改变之后)大于或等于 $T_i$ 时,第 $i$ 个实验才会发生反应。请注意,无论反应是否发生,第一步引起的温度变化都会持续保留。

Nicky 希望发生尽可能多的反应,以便收集尽可能多的数据。请通过计算这个最大反应次数来帮助他。

实现细节

你应该实现以下函数 reactions

int reactions(int N, std::vector<int> D, std::vector<long long> T)
  • $N$:计划进行的实验数量;
  • $D$:一个包含 $N$ 个整数的 vector,其中 $D_i$ 表示第 $i$ 个实验的温度变化量;
  • $T$:一个包含 $N$ 个整数的 vector,其中 $T_i$ 表示第 $i$ 个实验中发生反应所需的溶液最低温度。

对于每个测试用例,该函数将被调用一次。它必须返回如果合理选择起始实验,可以发生的最大反应次数。

数据范围

  • $1 \le N \le 500\,000$
  • $-10^9 \le D_i \le 10^9$
  • $-10^{15} \le T_i \le 10^{15}$

子任务

子任务 分值 依赖子任务 附加限制
0 0 - 样例
1 15 0 $N \le 2000$
2 15 0 最多有 20 个索引 $i$ 满足 $D_i < 0$
3 20 - 对所有 $0 \le i < N$,均有 $D_i \le 0$
4 20 0 答案最多为 20
5 30 0 - 4

样例

输入样例 1

5
1 1 -3 1 1
1 3 5 1 2

输出样例 1

2

说明 1

考虑以下调用:

reactions(5, {1, 1, -3, 1, 1}, {1, 3, 5, 1, 2})

如果 Nicky 选择从索引为 3 的实验开始,溶液的温度将变为 1,这满足该反应发生的条件。在下一个实验中,温度升高到 2,反应再次发生。由于无法发生超过 2 次反应,函数应返回 2。

输入样例 2

5
1 -3 0 3 2
0 -2 -1 0 3

输出样例 2

4

说明 2

考虑以下调用:

reactions(5, {1, -3, 0, 3, 2}, {0, -2, -1, 0, 3})

函数应返回 4,因为如果从索引为 0 的实验开始,Nicky 将在索引为 0、1、3 和 4 的实验中观察到反应。温度从 0 度开始,在每个实验期间的温度分别为:1, -2, -2, 1, 3。

评测程序示例

评测程序示例的输入格式如下:

  • 第 1 行:单个整数,表示 $N$ 的值。
  • 第 2 行:$N$ 个整数,表示 $D_0, D_1, \dots, D_{N-1}$。
  • 第 3 行:$N$ 个整数,表示 $T_0, T_1, \dots, T_{N-1}$。

评测程序示例的输出格式如下:

  • 第 1 行:单个整数,表示函数调用的返回值。

Discussions

About Discussions

The discussion section is only for posting: General Discussions (problem-solving strategies, alternative approaches), and Off-topic conversations.

This is NOT for reporting issues! If you want to report bugs or errors, please use the Issues section below.

Open Discussions 0
No discussions in this category.

Issues

About Issues

If you find any issues with the problem (statement, scoring, time/memory limits, test cases, etc.), you may submit an issue here. A problem moderator will review your issue.

Guidelines:

  1. This is not a place to publish discussions, editorials, or requests to debug your code. Issues are only visible to you and problem moderators.
  2. Do not submit duplicated issues.
  3. Issues must be filed in English or Chinese only.
Active Issues 0
No issues in this category.
Closed/Resolved Issues 0
No issues in this category.