Want to try solving this problem? You can submit your code online if you log in or register.
You run a poster advertisement company. Your company is quite small: all it owns is a rectangular wall in the city. Advertisers pay to put up their poster on your wall at some time at some position along the wall. These posters may have different widths, but are all exactly the same height as the wall. When a poster is put up, it may cover some of the posters already on the wall.
You have a log of every single poster put on your wall: their distance from the left end, their width, and the time they were put up.
Since people always walk from the left to the right of your wall, and we all know advertisement posters are only effective when they are completely uncovered (e.g. a burger picture will only be mouthwatering if you see the whole burger), you would like to determine the leftmost fully visible poster.
The first line will contain a single integer N, the number of posters that have been put up. The next N lines will contain descriptions of the posters in chronological order (from earliest to most recent). The ith of these lines will contain two integers xi and wi, which indicate the distance from the left end and the width of poster i respectively. (All units are in metres.)
Output should consist of a single integer: the index i of the leftmost, completely visible poster (where the index of the first poster is 1).
4 1 5 3 7 2 6 8 9
7 40 50 30 45 1 10 20 30 1 30 5 15 10 40
In the first sample case, the first and second posters are both partially covered by the third poster. While the fourth poster is completely visible, it is further to the right of the third poster and does not overlap it, so the third poster is the leftmost completely visible poster.
In the second sample case, the first poster is partially covered by the second, the second is partially covered by the seventh, the third and fourth are covered by the fifth, and the sixth is partially covered by the seventh. The seventh poster is the only completely visible poster.
To evaluate your solution, the judges will run your program against several different input files. All of these files will adhere to the following bounds:
As some of the test cases will be quite large, you may need to think about how well your solution scales for larger input values. However, not all the cases will be large. In particular:
The score for each input scenario will be 100% if the correct answer is written to the output file, and 0% otherwise.
© Australian Mathematics Trust 2001-2023
Page generated: 3 June 2023, 2:35pm AEST