Hi, I can help you.
Imagine this as a triangle with the width of 8cm and a height of 17cm.
l\
l \
17 cml \ c
l \
l____\
8cm
You need to find c you have to use A² + B² = C²
17² + 8² = C² 17² = 289 8²=64
289 + 64 = 353²
Then get square root √353²
SO c (the diagonal of the cylinder) is 18.78 cm. SO that means the 19 cm pencil won't fit in the cup