HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Volumes > Array and Matrices > problem:


50442 - Polynomial Addition

Guest
• Review clarifications (1)

Volume problems

• 50866 - Buy the cheapest
• 50785 - Swimming Contest
• 51011 - Decoding the Path
• 50515 - Lines - Revisited
• 50999 - Overlapping Trips
• 50507 - Sequential Numbers
• 50449 - The biggest result
• 50434 - Row Min Subtraction
• 50442 - Polynomial Addition
• 50869 - Birthday Celebration
• 50870 - ZScore normalization
• 50513 - Climbing Up the Stairs
• 50821 - Derivative of an array
• 50854 - Area of Triangle Revised
• 50520 - Filling a Matrix Randomly
• 51019 - Finding the hidden message
• 50497 - Falling Bricks - Revisited

Feedback

If you notice incorrect translations in Contester, please let author know.

Time limit 2000/4000/4000/4000 ms. Memory limit 65000/65000/65000/65000 Kb.
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


Для отправки решений необходимо выполнить вход.

www.contester.ru