#C6427. Folder Structure Storage Constraints

    ID: 50186 Type: Default 1000ms 256MiB

Folder Structure Storage Constraints

Folder Structure Storage Constraints

You are given a nested folder structure and a set of size constraints for specific folders. Each folder may contain files with integer sizes and subfolders. The size of a folder is defined recursively as the sum of the sizes of its files and all the files in its subfolders.

For each folder that has a constraint specified, the total computed size must not exceed the constraint. Formally, if a folder F has a computed size S and a constraint C, then the requirement is:

$$ S \le C $$

Your task is to determine if the entire folder structure satisfies all the given constraints.

The input will be provided as two JSON objects via standard input. The first JSON object represents the folder structure and the second represents the constraints. It is guaranteed that the root folder is named root.

inputFormat

The input consists of two lines:

  1. A JSON object representing the folder structure. In this structure, a key is either the name of a folder or a file. If the key maps to an object, it represents a subfolder; if it maps to an integer, it represents the size of a file.
  2. A JSON object representing the folder constraints. Each key is the name of a folder and its corresponding integer value is the maximum allowed total size for that folder.

outputFormat

Output a single line to standard output: True if the folder structure meets all the storage constraints; otherwise, output False.

## sample
{"root": {"subfolder1": {"file1.txt": 100, "file2.txt": 200}, "subfolder2": {"subsubfolder1": {"file3.txt": 150, "file4.txt": 100}, "file5.txt": 300}, "file6.txt": 400}}
{"root": 1250, "subfolder1": 400, "subfolder2": 600, "subsubfolder1": 300}
True