Purchasing Power (APCS 2021-01 Beginner)

Points 100 1.0s 256M

There are \(n\) products in the market, and you know the prices of these \(n\) products over the last \(3\) days.

You want to buy every product whose recent price fluctuates greatly, that is, every product for which the difference between the highest and lowest of its last three days' prices is at least \(d\). The cost of buying a product is the average of its last \(3\) days' prices (which is guaranteed to be an integer).

Given the last \(3\) days' prices of the \(n\) products and the value \(d\), output the total number of products bought and the total cost.

Input

The first line contains two integers \(n\) and \(d\), the number of products and the fluctuation threshold.

The next \(n\) lines each contain three integers, the last \(3\) days' prices of the \(i\)-th product.

Constraints

  • \(1 \le n \le 100\)
  • \(0 \le d \le 100\)
  • Every price is an integer in \([0, 100]\)
  • For every bought product (price range \(\ge d\)), the average of its \(3\) prices is guaranteed to be an integer

Output

On one line, output two numbers separated by a space: the number of products bought and the total cost.

Scoring

The time limit for each test case is \(1\) second; your score is the sum over the test cases you pass. The subtasks are:

  • Subtask 1 (\(50\) points): \(n = 1\).
  • Subtask 2 (\(50\) points): \(1 \le n \le 100\).

Sample Input 1

1 3
24 27 21

Sample Output 1

1 24

Sample Explanation 1

The range is \(27 - 21 = 6 \ge 3\), so it is bought; the average is \((24+27+21)/3 = 24\).

Sample Input 2

3 4
24 33 42
51 48 60
77 77 77

Sample Output 2

2 86

Sample Explanation 2

Product \(1\) has range \(18 \ge 4\), average \(33\); product \(2\) has range \(12 \ge 4\), average \(53\); product \(3\) has range \(0 < 4\) and is not bought. Two products are bought, for a total of \(33 + 53 = 86\).

Source

APCS programming exam, January 2021, Problem 1.

Problem page help

Keyboard shortcuts

Main features

  • Sample tests — Runs the sample cases bundled with the problem and auto-compares against the expected output.
  • Custom test — Run your code with your own stdin. Optionally tick the "Compare with expected (diff)" box to verify against expected output line-by-line.
  • Template — Paste the default code template you set on your profile page.
  • Collab — Edit this problem together with classmates in real time.
  • Auto-draft — Editor contents auto-save to your browser every 1.5 seconds (per account / problem / language).
  • Submit — Send your code to the judge for grading; returns AC / WA / TLE etc.

Limits

  • Source code: at most 65,536 characters
  • Custom test stdin and expected output: at most 1 MB each (≈1 million characters)
  • Custom test and sample test share the sandbox; about 1 request per 3 s per user (sample test: 1 per 1 s)
  • Custom test and sample test both have a 15 second wall-clock cap (the official judge still uses the problem time limit)
  • Interactive problems do not offer custom test (cannot simulate interaction with the judge).
  • Submitting has no rate limit, but rapid repeated submissions on the same problem are treated as score farming.