The Spy
Time limit1sMemory limit256 MB
Given difference constraints on N product scores in 0 to 100, find the smallest possible gap between the highest and lowest score, or -1 if no assignment exists.
- Level
Hard8 of 10
- Topics
- Shortest path, Graph, Binary search, Math
- Solved
- No attempts yet
Problem
SPARCS Company, whose chairman is Seokju, decided to release new products. Its beta testers agreed among themselves and gave every new product an integer score from 0 to 100.
Jihoon, a spy from the rival GoN Company, asked each of the beta testers one question and got one piece of information about the scores out of each of them. Information comes in three kinds.
1 a b c: (score of product ) (score of product )2 a b c: (score of product ) (score of product )3 a b c: (score of product ) (score of product )
Jihoon tried to pin down the best rated product and the worst rated one, but the information does not go that far. Find the smallest possible value of (highest score) (lowest score) instead.
Input
The first line contains and . (, )
Each of the next lines contains one piece of information Jihoon obtained, in the format above. (, , )
Output
Print the smallest possible value of (highest score) (lowest score) over all score assignments that satisfy every piece of information and give each product an integer score from 0 to 100. If no such assignment exists, print -1.