Given how many buns were eaten, find which person picked up the last bun when person i grabs a bun at multiples of t_i, ties broken by smaller index.
Medium6Binary searchSortingMathNo attempts yetTime limit1sMemory limit512 MBYeongseon came back from Daejeon with n fried soboro buns.
She left them in the club room to share with the members and stepped out for a moment. When she got back, s buns were untouched. A bun that someone had picked up to eat does not count among those s.
While Yeongseon was away, m people were in the room, numbered 1 to m. She eats with the members often, so she knows ti, the number of seconds person i needs to eat one bun.
Everyone picks up a bun the moment Yeongseon leaves, at second 0, and picks up the next bun as soon as the one in hand is finished. So person i picks up a bun at seconds 0, ti, 2ti, 3ti, and so on. When several people pick at the same moment, the person with the smaller number picks first.
Find the number of the person who picked up a bun last.
For example, suppose person 1 eats one bun in 1 second, person 2 in 3 seconds, person 3 in 5 seconds, and there are 1000 buns.
The first line contains n and s separated by a space. n is the number of buns Yeongseon bought (1≤n≤100000), and s is the number of untouched buns left when she returned (0≤s≤n−1).
The second line contains the number of people m (1≤m≤100000). Each of the next m lines contains ti, the number of seconds one person needs to eat one bun, given for person 1 through person m in order (1≤ti≤1000).
Print the number of the person who picked up a bun last.