Sponsored
Sponsored
Use these hints if you're stuck. Try solving on your own first.
Simulate the process.
We only need to keep track of the times when a piston reaches one end and let’s call these critical points.
For each piston, find the first time it reaches one end and sort these times (these times are critical points).
Find a way to calculate the area difference between two consecutive critical points in constant time.