#K81622. Approximately Equal Dictionaries
Approximately Equal Dictionaries
Approximately Equal Dictionaries
You are given two dictionaries \(A\) and \(B\) along with a tolerance value \(t\). The dictionaries are considered approximately equal if they have exactly the same set of keys and for each key \(k\) in the dictionaries, the following inequality holds:
\( |A[k] - B[k]| \le t \)
If either the set of keys differ or any corresponding value pair fails this inequality, the dictionaries are not approximately equal.
Your task is to determine whether the two dictionaries are approximately equal. Print YES
if they are approximately equal; otherwise, print NO
.
inputFormat
The input is given via standard input and has the following format:
- An integer \(m\) representing the number of key-value pairs in dictionary \(A\).
- \(m\) lines follow, each containing a key (a string without spaces) and a floating point number separated by space, representing a key-value pair of \(A\).
- An integer \(n\) representing the number of key-value pairs in dictionary \(B\).
- \(n\) lines follow, each containing a key and a floating point number separated by space, representing a key-value pair of \(B\).
- A floating point number \(t\) representing the tolerance.
Note that the keys in the dictionaries are case-sensitive.
outputFormat
Output a single line via standard output: YES
if the two dictionaries are approximately equal; otherwise, output NO
.
3
apple 10.5
banana 20.3
cherry 5.2
3
apple 10.6
banana 20.2
cherry 5.0
0.3
YES