#C3206. Total Salary Calculation

    ID: 46608 Type: Default 1000ms 256MiB

Total Salary Calculation

Total Salary Calculation

This problem asks you to compute the total salary expense of a company. The company's organizational structure is given as a nested JSON object where each department may contain sub-departments and an employees list. Each employee is an object that has at least a salary field.

Your task is to recursively traverse the company structure and sum the salaries of all employees. In mathematical notation, if the total salary of a department is \( S \), then it can be defined as:

\( S = \sum_{e \in \text{employees}} e.\text{salary} + \sum_{d \in \text{subdepartments}} S_d \)

The solution must read input from stdin and produce the output to stdout.

inputFormat

The input is a valid JSON string read from standard input that represents the company structure. It is a JSON object where each key is a department name. Each department is represented by an object that may contain:

  • An employees field with an array of employee objects.
  • Other nested objects representing sub-departments.

Each employee object has a salary key (with an integer value) and possibly other keys.

outputFormat

Output a single integer representing the total sum of salaries of all employees in the company. The result should be printed to standard output.

## sample
{"HR": {"recruitment": {"employees": [{"name": "Alice", "salary": 50000}, {"name": "Bob", "salary": 60000}], "training": {"employees": [{"name": "Charlie", "salary": 55000}]}}, "IT": {"development": {"backend": {"employees": [{"name": "Dave", "salary": 70000}, {"name": "Eve", "salary": 80000]}, "frontend": {"employees": [{"name": "Frank", "salary": 75000}]}}, "support": {"employees": [{"name": "Grace", "salary": 50000}]}}}
440000