Maxplus
Time limit1sMemory limit128 MB
Given 3x3 integer matrices A and C, find the entrywise-largest integer matrix B with A (max-plus) B = C, or report that none exists.
- Level
Hard8 of 10
- Topics
- Math, Matrix, Greedy, Implementation
- Solved
- No attempts yet
Problem
Max-plus algebra works over the real numbers with only two binary operations: the maximum operation and the addition operation . The operation binds tighter than .
For example, , , , and .
Applications of this algebra often use the max-plus product of two matrices, . The product is defined the same way as the ordinary matrix product, except that the multiplication sign becomes (addition) and the addition sign becomes (maximum).
This problem only deals with the max-plus product of integer matrices.
Here , so is the largest of the three sums of matching entries.
For example, the following holds.
You are given the matrices and . Every entry of both matrices is an integer with absolute value less than 100. Write a program that finds a matrix whose entries are integers with absolute value less than 1000 and that satisfies , or reports that no such matrix exists.
Input
The first three lines contain three integers each, the matrix .
The next three lines contain three integers each, the matrix .
Every number is an integer with absolute value less than 100.
Output
If no matrix satisfies , print nemoguce on the first and only line.
Otherwise print the matrix on three lines, three integers per line, separated by single spaces.
Several matrices can satisfy . Print the one whose every entry is greater than or equal to the entry in the same position of every other valid matrix. Whenever at least one valid matrix exists, that matrix exists and is unique, and all of its entries have absolute value less than 1000.