Does the Line Beat Guessing the Mean?
Before Kestrel Freight ships a fuel rule, someone has to ask whether it is worth having at all. The honest thing to beat is the laziest possible rule: ignore the distance entirely and quote every job at the average of the costs already recorded. If a fitted line cannot beat that, it is dressing up a guess. The comparison is on total squared residuals — for each delivery, the gap between what is predicted and what it really cost, squared, added across every delivery — with the line judged on its own predictions and the lazy rule judged on that single average cost.
Task: Print whether the given line does better than always quoting the average recorded cost.
Input
The first line holds two numbers separated by a single space: the line's slope, then its intercept. The second line holds one integer n, the number of deliveries, where 1 <= n <= 1000. Then come n lines, each holding a distance and the real cost, separated by a single space.
Output
One line, exactly line helps if the line's total is strictly lower than the lazy rule's total, and exactly line does not help otherwise. Equal totals count as no help.
Example:
Input:
2 1
5
1 3
2 5
3 7
4 9
5 11
Output:
line helps
Sign in to solve this problem
Reading problems is free for everyone — solving them (Run, Submit, and tracking what you've solved) needs an account.
Sign in