#P14003. [eJOI 2025] Reactions

    ID: 15791 远端评测题 2500ms 256MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>线段树平衡树树状数组2025离散化交互题eJOI(欧洲)

[eJOI 2025] Reactions

题目描述

Nicky is conducting experiments on chemical reactivity. He has prepared NN experiments, which are indexed from 00 to N1N - 1. Now he needs to choose his starting experiment, and then he will conduct all the experiments with indices greater than or equal to that of the chosen one. In other words, if he decides to start from experiment with index SS, he will run experiments S,S+1,,N1S, S + 1, \ldots, N - 1 in this order.

Before the starting experiment, he has a container with a solution. The temperature of the solution is equal to 0 degrees. During the ii-th experiment (0iN10 \leq i \leq N - 1), he performs the following two steps in this order:

  1. Changes the temperature of the solution by a given integer number of degrees (it can increase or decrease by an arbitrary amount, or remain the same);
  2. Performs an experiment and checks whether a reaction takes place.

It is known that for the ii-th experiment, the temperature changes by DiD_i degrees - the temperature increases if Di>0D_i > 0, decreases if Di<0D_i < 0, or remains the same if Di=0D_i = 0. Moreover, the reaction in the ii-th experiment occurs only if the current temperature (after the change) is greater than or equal to TiT_i. Note that the temperature change from the first step persists regardless of whether the reaction occurs or not.

Nicky wants to have the largest number of reactions occurring so that he can gather as much data as possible. Help him by calculating this number.

Implementation details

You should implement the function reactions:

int reactions(int N, std::vector<int> D, std::vector<long long> T)
  • NN: the number of planned experiments;
  • DD: a vector of NN integers, where DiD_i represents the change in temperature for the ii-th experiment;
  • TT: a vector of NN integers, where TiT_i represents the minimal temperature of the solution for a reaction to occur during the ii-th experiment.

This function will be called once for each test. It has to return the maximum number of reactions which can occur if the starting experiment is chosen appropriately.

输入格式

The input format is the following:

  • line 1: a single integer - the value of NN.
  • line 2: NN integers - D0,D1,,DN1D_0, D_1, \ldots, D_{N-1}.
  • line 3: NN integers - T0,T1,,TN1T_0, T_1, \ldots, T_{N-1}.

输出格式

The output format is the following:

  • line 1: one integer - the return value of the call.
5
1 1 -3 1 1
1 3 5 1 2
2
5
1 -3 0 3 2
0 -2 -1 0 3
4

提示

Example 1

Consider the following call:

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

If Nicky chooses to start from experiment with index 3, the temperature of the solution will become 1 which satisfies the constraints for that reaction to take place. During the next experiment the temperature increases to 2 and a reaction occurs again. Since there is no way for more than 2 reactions to occur, the function should return 22.

Example 2

Consider the following call:

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

The function should return 4 because starting from experiment with index 0 Nicky will observe reactions during the experiments with indices 0, 1, 3 and 4. The temperature starts at 0 degrees and during each experiment the temperature is: 1,2,2,1,31, -2, -2, 1, 3.

Constraints

  • 1N5000001 \leq N \leq 500\,000
  • 109Di109-10^9 \leq D_i \leq 10^9
  • 1015Ti1015-10^{15} \leq T_i \leq 10^{15}

Subtasks

Subtask Points Required subtasks Additional constraints
0 - The examples.
1 15 0 N2000N \leq 2000
2 There are at most 20 indices ii for which Di<0D_i < 0.
3 20 - Di0D_i \leq 0 for each 0i<N0 \leq i < N
4 0 The answer is at most 20.
5 30 0 - 4 -