HomeVolumesContestsSectionsForumsUsersPrintHelpAbout

Sections > Linear Data Structures: Arrays > problem:


50442 - Polynomial Addition

Guest
• Review clarifications (1)

Section problems

• 50876 - He is my cousin
• 50829 - Decode an Image
• 50851 - Repeated Numbers
• 50838 - Balanced Numbers
• 50515 - Lines - Revisited
• 50913 - Manhattan Distance
• 50824 - Sum of Group Maxes
• 50449 - The biggest result
• 50442 - Polynomial Addition
• 50982 - A thief in labyrinth
• 50989 - Rectangles and Points
• 50932 - Shifting rows and columns
• 50497 - Falling Bricks - Revisited
• 50933 - Sum of the Biggest Neighbors
• 50444 - n digit kth number divisible...
• 50865 - Apartment Building Adminis...
• 50874 - Apartment Building Adminis...

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