P27847 [洛谷] [Language Monthly Contest 202306] Classroom
普及-
题目描述

Problem Description

Zyl has arrived at a new classroom, and the math teacher wants him to help arrange the desks.

The teacher requires that the total number of desks be the same as the total number of students, but Zyl does not know how many students are in the class.

At the back of the classroom, there are $n$ cabinets, numbered from $1$ to $n$. The $i$-th cabinet consists of $a_i \times b_i$ compartments, and each compartment is shared by $c_i$ students. Each student will and will only use one compartment in one cabinet. That is, the $i$-th cabinet will be used by $a_i \times b_i \times c_i$ students.

With this information, Zyl can calculate the total number of students.

Now, the desks need to be arranged in $m$ columns, and Zyl wants to arrange them into a neat rectangle as much as possible. If there are a few desks left that cannot form a complete row, these desks will be placed in a new row after the last row.

Zyl wants to know how many rows there will be in total after all the desks are arranged, and how many desks will be in the last row.

Input Format

The input consists of $n+1$ lines.

The first line contains two integers $n$ and $m$, representing the number of cabinets and the number of desk columns, respectively.
The next $n$ lines each contain three integers $a_i$, $b_i$, and $c_i$, describing the information of the $i$-th cabinet.

Output Format

The output consists of one line with two integers, representing the total number of rows and the number of desks in the last row after arranging all the desks, separated by a space.

Sample Input and Output

Sample Input #1

3 8
2 3 3
4 1 3
2 5 2

Sample Output #1

7 2

Sample Input #2

2 4
1 2 2
2 3 2

Sample Output #2

4 4

Notes

Sample 1 Explanation

The first cabinet has $2$ rows and $3$ columns, and each compartment is used by $3$ students, so this cabinet has a total of $6$ compartments and is used by $18$ students.

Similarly, the next two cabinets are used by $12$ and $20$ students, respectively, so there are a total of $50$ students, which means there are $50$ desks in the class.

The desks need to be arranged in $8$ columns. First, each column is arranged with $6$ desks, resulting in $6$ rows. Then, the remaining $2$ desks are placed after the $6$th row, forming the $7$th row. Thus, there are a total of $7$ rows, with $2$ desks in the $7$th row.

Data Range and Constraints

For $40\%$ of the data, the desks can be arranged into a perfect rectangle as required.

For $100\%$ of the data, $1 \leq n \leq 100$, $1 \leq a_i, b_i, c_i \leq 10$, $1 \leq m \leq 50$.

输入格式

见题面 Input 部分

输出格式

见题面 Output 部分

样例输入
3 8 2 3 3 4 1 3 2 5 2
样例输出
7 2