let the age of A be x and B be y
given that sum of the age is 30
x+y=30-----1
now given that after 5 years A will be 3 times older than B
that is
after 5 year
age of A will be x+5
age of B will be y+5
so given
x+5=3(y+5)
x+5=3y+15
x=3y+15-5
x=3y+10
now put x= 3y+10 eqn 1
x+y=30
(3y+10)+y=30
4y=30-10
4y=20
y=5
so we got age of the B that is 5
now we have
x=3y+10
=3(5)+10=25
so age of A IS 25
B is 5