Not One of Them

0

0 votes
Medium
Problem

"You need me or you're nothing. Because we're just alike, you and I. Except you're boring. You're on the side of the angels". -Moriarty

Problem 7

On the auspicious occasion of New Year, a marathon tournament is being organised in your society.

There are a total of N participants registered for the marathon. There are Q time breaks available for the whole marathon.

In order to make the marathon unique and successful, the organizers have come up with a new format this year. Apart from the usual winner of the marathon, the organizers have decided to award the participant that is currently last in the marathon with a special prize. They have also imposed this absurd rule that the participants can never increase their speed in the whole marathon.

All the participants start at the same point and move in the same direction. Some participants may speed down for the special prize. The change of speed takes place immediately. The rest of the time, they move with a constant speed.

More formally, for each query, you need to do 2 things :-

  • Output the participant which is last in the marathon at time t along with the total distance covered by him.
  • Reduce the speed of the pth participant by v at time t.

In case of multiple participants occupying the last position, answer the one having larger index.

Input:

First line of input contains 2 integer N and Q, denoting the number of participants and the queries. Next lines contains N integers where Vi denotes the initial speed of the ith participant. Next Q lines contain 3 integers pi, ti and vi denoting that the speed of pith participant is decreased by vi at the time ti.

Output:

Each of the Q lines should contain 2 integers, the currently winning participant and its position from the starting point.

Constraints:

1N50000

1Q105

1ti109

ti<ti+1

1vi106

1piN

1Vi1010

Note:

The speed of any participant will never be <0 at any point of time.

This problem has binary scoring. You will get 100 points if you pass all test cases.

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?