Are the Residuals Balanced?
Kestrel Freight's auditors do not trust a fuel rule that has been hand-tuned, and they have one cheap test for it. A properly fitted line leaves its misses balanced: the deliveries it over-quotes cancel the ones it under-quotes. A rule that has been nudged up or down leans the same way on every job, and the misses stop cancelling. The audit therefore adds up the residuals with their signs kept — a residual being the real cost minus the quoted cost, so over-quoting gives a negative one — and reports both the total and its verdict.
Task: Print the signed total of the residuals, then whether the rule is balanced.
Input
The first line holds two numbers separated by a single space: b0, the rule's intercept, then b1, its slope. 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
Two lines. The first is the word sum_residuals, a single space, and the signed total rounded to 4 decimal places — a total, not an average, and the minus sign is kept if there is one. The second is balanced when that total is smaller than 0.01 in size, ignoring its sign, and biased otherwise.
Example:
Input:
1 2
3
1 3
2 5
3 7
Output:
sum_residuals 0.0000
balanced
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