[HackerRank] Jim and the Orders (JAVA)
문제
Jim's Burgers has a line of hungry customers. Orders vary in the time it takes to prepare them. Determine the order the customers receive their orders. Start by numbering each of the customers from 1 to n, front of the line to the back. You will then be given an order number and a preparation time for each customer.
The time of delivery is calculated as the sum of the order number and the preparation time. If two orders are delivered at the same time, assume they are delivered in ascending customer number order.
For example, there are n = 5 customers in line. They each receive an order number order[i] and a preparation time prep[i].:
We see that the orders are delivered to customers in the following order:
입력
Complete the jimOrders function in the editor below. It should return an array of integers that represent the order that customers' orders are delivered.
jimOrders has the following parameter(s)
orders: a 2D integer array where each orders[i] is in the form [order[i], prep[i]].
출력
Print a single line of n space-separated customer numbers (recall that customers are numbered from 1 to n) that describes the sequence in which the customers receive their burgers. If two or more customers receive their burgers at the same time, print their numbers in ascending order.
제한
1 <= n <= 103
1 <= i <= n
1 <= order[i], prep[i] <= 106
풀이
간단한 구현 문제였습니다.
손님은 1번부터 n번까지 있고, 각 손님당 주문 번호와 준비 시간이 주어집니다. 우리가 해야할 일은 각각의 손님의 제공 시간(주문 번호 + 준비 시간)을 구하고, 제공 시간을 오름차순 정렬한 순서대로 손님의 순서를 변경하는 것입니다.
아래 소스코드를 참고해 보시길 바랍니다.
소스코드
지적 혹은 조언 환영합니다! 언제든지 댓글로 남겨주세요.
'PS > HackerRank' 카테고리의 다른 글
[HackerRank] Pairs (JAVA) (0) | 2021.01.09 |
---|---|
[HackerRank] Forming a Magic Square (JAVA) (0) | 2020.12.29 |
[HackerRank] The Power Sum (JAVA) (0) | 2020.12.28 |
[HackerRank] Lily's Homework (JAVA) (0) | 2020.12.27 |
댓글