In McD's Burger, n hungry burger fans are ordering burgers. The ith order is placed by the ith fan at ti time and it takes di time to procees. What is the order in which the fans will get their burgers?
Input Format
On the first line you will get n, the number of orders. Then n lines will follow. On the (i+1)th line, you will get ti and di separated by a single space.
Output Format
Print the order ( as single space separated integers ) in which the burger fans get their burgers. If two fans get the burger at the same time, then print the smallest numbered order first.(remember, the fans are numbered 1 to n).
Constraints
1≤n≤103
1≤ti,di≤106
SAMPLE INPUT
5
8 1
4 2
5 6
3 1
4 3
SAMPLE OUTPUT
4 2 5 1 3
Explanation
The first order is placed at time 3 and it takes 1 unit of time to process, so the burger is sent to the customer at time 4.
The second order is placed at time 4 and it takes 2 units of time to process, the burger is sent to customer at time 6.
The third order is placed at time 4 and it takes 3 units of time to process, the burger is sent to the customer at time 7.
Similarly, the fourth and fifth orders are sent to the customer at time 9 and time 11.
So the order of delivery of burgers is, 4 2 5 1 3.
Assistant
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.
We need to parse the problem: It's about ordering burgers. There are n orders, each order i has a placement time t_i and processing time d_i. We need to output the order in which the fans receive their burgers (i.e., the sequence of order indices based on completion times). If two fans get the burger at the same time, then we print the smallest numbered order first.
This is essentially a scheduling problem: we have orders arriving at times t_i, each takes d_i to process. The typical model is that orders are processed sequentially by a single server? Or maybe they are processed concurrently? Let's read the sample.
Input:
5
8 1
4 2
5 6
3 1
4 3
Output: 4 2 5 1 3
We need to deduce the interpretation.
If it's a single server processing orders in order of arrival (FIFO), then the completion times would be determined by queue. Let's simulate.
Sort by arrival time? Usually FIFO queue: When an order arrives, if server is free, it starts processing immediately; else it waits. Completion time = max(current_time, t_i) + d_i.
But sample output says order of completion: indices 4,2,5,1,3.
Compute completions under FIFO:
We need to sort orders by arrival time? But arrival times are not sorted. Typically in such problems, orders are processed based on the earliest available time, often using a priority queue (like shortest job first?). However, they ask: "What is the order in which the fans will get their burgers?" It could be that they are processed in the order they become available? Actually, let's simulate FIFO with given indices as they are given? Usually, orders are placed at times, but they are processed as they come, but if multiple orders arrive at same time, we might need to decide order. Typically, in such problems, we use the concept: at any moment when the burger is ready, among all orders that have already been placed, the one with smallest processing time is chosen? That is like a shortest job first? But sample output might reveal.
Let's compute FIFO by sorting by arrival time (and if tie, perhaps by index? Or by order of input?).
Sort by t_i ascending, then if ties, maybe by index? Let's list:
Indices with t:
4: t=3
2: t=4
5: t=4
3: t=5
1: t=8
If tie at t=4, we have indices 2 and 5. Which one first? Typically, the input order might matter? But the problem statement: "the ith order is placed by the ith fan at ti time and it takes di time to process." It doesn't specify processing order. We need to infer from output.
Let's simulate FIFO processing in order of increasing t_i, and for ties, perhaps by index? Let's try both.
Case: process in order: 4, then 2, then 5, then 3, then 1.
Initialize time=0? Actually, at time 0, no orders. Process order 4: arrives at 3, so start at max(time,3)=3, complete at 3+1=4, time=4.
Next order 2: arrives at 4, start at max(4,4)=4, complete at 4+2=6, time=6.
Next order 5: arrives at 4, but already arrived at 4, but since we process in order, after order 2 we go to order 5. At time=6, start=max(6,4)=6, complete at 6+3=9, time=9.
Next order 3: arrives at 5, start=max(9,5)=9, complete at 9+6=15, time=15.
Next order 1: arrives at 8, start=max(15,8)=15, complete at 15+1=16, time=16.
Completions: order4 at4, order2 at6, order5 at9, order3 at15, order1 at16. Order of completion: 4,2,5,3,1. But sample output is 4,2,5,1,3. So order of 1 and 3 are swapped. In this simulation, order1 completes at16, order3 at15 => order3 before order1. But output shows 1 before 3.
Thus FIFO with sorting by arrival (and tie by index) yields 4,2,5,3,1, not matching.
What if we process in order of input index? i.e., order1,2,3,4,5 as they are given? But that would be unrealistic because orders arrive at different times. Let's simulate:
Start time=0.
Order1: arrives at 8, start at max(0,8)=8? Actually, at time0 we have no order; we need to handle arrival: At time we begin, we might wait for first order. So simulate sequentially:
Process order1 first: but it hasn't arrived yet? Actually if we process in order of index, we might start at time0, but we must consider that we can't process order1 before its arrival. So we would wait until time8, then process for 1, complete at9. time=9.
Order2: arrives at4. At time9, it's already arrived, so start at9, complete at11, time=11.
Order3: arrives at5, start at11, complete at17, time=17.
Order4: arrives at3, start at17, complete at18, time=18.
Order5: arrives at4, start at18, complete at21, time=21.
Order of completion: 1,2,3,4,5. Not matching.
Thus that's not.
Maybe it's not a single server but each order is processed independently? That is, each fan starts preparing at time ti? But then completion times would be ti+di. Let's compute:
Sort by completion time: earliest: 4 (4), then 2 (6), then 5 (7), then 1 (9), then 3 (11). That gives order: 4,2,5,1,3. That matches sample output exactly! Indeed, sample explanation says: "The first order is placed at time 3 and it takes 1 unit of time to process, so the burger is sent to the customer at time 4." That suggests that each order is processed independently and the burger is ready at ti+di, and there is no queuing or shared resource. Actually, the explanation: "The first order is placed at time 3 and it takes 1 unit of time to process, so the burger is sent to the customer at time 4." That is simply ti+di. They then list second order at 4+2=6, third at 4+3=7, fourth (order1) at 8+1=9, fifth (order3) at 5+6=11. So indeed they are just sorting by ti+di. And tie-breaking: if same completion time, then smallest index first.
Thus the problem is simply: Given n orders each with t_i and d_i, compute completion time c_i = t_i + d_i. Sort orders by c_i ascending; if c_i equal, sort by index i ascending. Output the indices in that sorted order.
But wait: The sample output is 4 2 5 1 3. Let's check c_i:
order4:3+1=4
order2:4+2=6
order5:4+3=7
order1:8+1=9
order3:5+6=11
That's ascending. Yes.
Thus the problem is trivial: compute sum and sort.
But is there any catch? The constraints: n up to 1000, ti,di up to 1e6. So O(n log n) is fine.
But why would they phrase as "n hungry burger fans are ordering burgers"? And earlier in typical problems like "Jim and the Orders" or "Minimum Average Waiting Time", we have queue processing. However here it seems it's simply sum.
Maybe there is a nuance: It says "If two fans get the burger at the same time, then print the smallest numbered order first." That fits with sorting by completion time and then index.
Thus the solution: read n, then for i from 1 to n, read t_i and d_i. Compute finish = t_i + d_i. Store tuple (finish, i). Sort by finish, then i. Print i's.
Double-check with sample.
Thus answer is straightforward.
But wait, is there any hidden scenario where processing order matters? The problem statement: "In McD's Burger, n hungry burger fans are ordering burgers. The ith order is placed by the ith fan at ti time and it takes di time to process. What is the order in which the fans will get their burgers?" Usually, such problems like "Jim and the Orders" on HackerRank is exactly this: sort by sum. Indeed, Jim and the Orders: Each order has order time and processing time, you need to output the order in which customers get their orders. That problem's solution is to sort by sum t_i + d_i, with ties by index. Yes, that is a known problem.
So it's definitely that.
Thus we'll produce Python code.
Implementation:
def main():
import sys
data = sys.stdin.read().strip().split()
if not data: return
n = int(data[0])
orders = []
idx = 1
for i in range(1, n+1):
t = int(data[idx]); d = int(data[idx+1])
idx += 2
orders.append((t+d, i))
orders.sort(key=lambda x: (x[0], x[1]))
result = ' '.join(str(i) for _, i in orders)
print(result)
Edge cases: ties handled by sorting.
Thus final answer: simple sorting.
But need to ensure correct for large n.
I'll produce code with proper input parsing.
Potential pitfalls: Input may have extra spaces, newlines; reading all tokens works.
Thus final answer.
But the user request: probably they want the solution description and code? Since this is a typical coding problem, we need to output the answer code and explanation.
I think the response should include explanation and code.
Thus in final answer, I'll provide the solution.
Given that the problem is from a coding platform, we can provide Python code.
Thus final answer: Python solution. ```python
import sys
def main():
data = sys.stdin.read().strip().split()
if not data:
return
n = int(data[0])
orders = []
idx = 1
for i in range(1, n + 1):
t = int(data[idx])
d = int(data[idx + 1])
idx += 2
orders.append((t + d, i)) # (finish time, original index)
code
# Sort by finish time, break ties by original index
orders.sort(key=lambda x: (x[0], x[1]))
result = ' '.join(str(i) for _, i in orders)
print(result)