Solution
The pictures occupy units of the wall's length. This leaves units for the gaps.
There are gaps between pictures. Including the gaps at both edges of the wall, there are n+1 gaps.
All gaps must have the same integer length. Therefore, an arrangement exists if and only if l-n \cdot w is divisible by n+1. Print YES in this case and NO otherwise.
The guarantee n \cdot w \le l ensures that the gap length is non-negative. If the pictures occupy the entire wall, all gaps have length zero, which is allowed.
Complexity
The time complexity is and the extra space is .