ECOCLASS Editorial

PROBLEM LINK:

Contest Division 1
Contest Division 2
Contest Division 3
Contest Division 4

Setter: Utkarsh Gupta
Tester: Aryan, Takuki Kurokawa
Editorialist: Pratiyush Mishra

DIFFICULTY:

Cakewalk

PREREQUISITES:

Basic Array Traversal

PROBLEM:

Alice has recently learned in her economics class that the market is said to be in equilibrium when the supply is equal to the demand.

Alice has market data for N time points in the form of two integer arrays S and D. Here, Si denotes the supply at the i_{th} point of time and D_i denotes the demand at the i_{th} point of time, for each 1≤i≤N.

Help Alice in finding out the number of time points at which the market was in equilibrium.

EXPLANATION:

The market is said to be in equilibrium when the demand = supply at a particular point of time. The problem wants us to calculate the number of instances of time where the values in the supply array equal those in the demand array.

More formally, Chef wants to find the number of times:
supply[i] = demand[i] \forall, i \in s.t. 0 \le i \lt length(supply or demand array)

TIME COMPLEXITY:

To iterate the two arrays together, we require O(N) time, which is in accordance with the array size.

SOLUTION:

Editorialist’s Solution
Setter’s Solution
Tester-1’s Solution
Tester-2’s Solution