Лимит времени 2000/4000/4000/4000 мс. Лимит памяти 65000/65000/65000/65000 Кб. Question by Ibrahim Mesecan.
Polynomial Addition
In general, polynomials are represented in the form
(see the figure on right)
where there are variables with different non-negative
integer exponents and each is multiplied with a coefficient.
Polynomials involve only the operations of addition,
subtraction, and multiplication.
e.g. the following is a quadratic polynomial
(of variable x),
2x2 - 4x + 7
which can be represented in the form
2 2 -4 1 7 0
Question:
Write a program that accepts two polynomils
and returns sum of them.
Input specification
You will be first given two integers (n and m) where
n is the length of the first and m is the length of the
second polynomial.
The second line will contain n number pairs (coefficient
and exponent) for the
first polynomial. And, the third line will contain
m number pairs for the second polynomial where
1 ≤ (n, m) ≤ 20 and coefficients are
between -1000 and 1000 and exponents are
between 0 and 20.
Note: Polynomials can
be in any order.
Output specification
Show the resulting polynomial in descending
order exponents.
Note: Show information
for any coefficient different than 0.
Sample Input
3 3
1 0 -5 8 3 14
8 14 -3 10 9 8
|
Sample Output
11 14 -3 10 4 8 1 0
|
Для отправки решений необходимо выполнить вход.
|