#P7267. Time Zone Reconstruction
Time Zone Reconstruction
Time Zone Reconstruction
Given an integer \(n\) representing the total number of time zones, numbered from \(0\) to \(n-1\), you are located in time zone \(0\). You receive \(n\) messages from different locations. Each message contains a time represented by two integers \(hh\) and \(mm\), where \(hh\) (the hour) and \(mm\) (the minute) satisfy \(0 \le hh \le n-1\) and \(0 \le mm \le 59\).
The sender originally set their clock in their own time zone. When sending the message, the sender’s local time is converted to your time zone (time zone \(0\)) by crossing time zone boundaries. For each time zone boundary crossed, the hour value shifts by exactly \(1\) (i.e. if the sender is in time zone \(i\), then the conversion is performed by subtracting \(i\) from the local hour). Note that no adjustment causes the hour value to go outside the range \([0, n-1]\); in other words, if a message originally set to local time \(L\) in time zone \(i\) is converted into your time zone, the resulting hour is computed as
[ \text{Received } hh = L - i\quad \text{with}\quad 0 \le L \le n-1,. ]
Since the conversion does not allow the resulting hour to go out of the range \([0, n-1]\), it must be that
[ i \le n-1 - hh,. ]
Your task is to determine, for each of the \(n\) received messages, which time zone (i.e. the value of \(i\)) the message originally came from. It is guaranteed that the messages were produced with a valid unique assignment of time zones \(0,1,\dots, n-1\) such that for each message with received hour \(hh\), the sender’s time zone \(i\) satisfies
[ i \le n-1 - hh,. ]
</p>You are given \(n\) and then \(n\) lines each containing \(hh\) and \(mm\). For each message, output the time zone number from which it originated.
inputFormat
The first line contains an integer \(n\) (the number of time zones/messages). \(n\) lines follow, each containing two integers \(hh\) and \(mm\) separated by spaces, representing the hour and minute respectively.
Constraints:
- \(1 \le n \le 10^5\) (or a suitable limit)
- \(0 \le hh \le n-1\)
- \(0 \le mm \le 59\)
outputFormat
Output \(n\) integers in one line separated by spaces. The \(j\)-th integer is the original time zone number of the \(j\)-th message (in the order of input) such that if the sender’s local hour is \(L\), then \(L = hh + i\) and \(L \le n-1\).
sample
3
1 15
0 30
2 45
1 2 0