Type the Question

Thursday, February 21, 2019

Question Name: JIM AND THE ORDERS

#include <bits/stdc++.h>

using namespace std;

int N;
pair<int, int> A[1000];

int main()
{
    scanf("%d", &N);
    int a, b;
    for(int i=0; i<N; i++)
    {
        scanf("%d%d", &a, &b);
        A[i]=make_pair(a+b, i+1);
    }
    sort(A, A+N);
    for(int i=0; i<N; i++)
        printf("%d ", A[i].second);
    printf("\n");
    return 0;
}
  • Problem Description
    Jim’s Burgers has n hungry burger fans waiting in line. Each unique order, i,is placed by a customer at time ti, and the order takes di units of time to process.

    Given the information for all n orders, can you find and print the order in which all n customers will receive their burgers? If two or more orders are fulfilled at the exact same time t, sort them by ascending order number.

    Input Format

    The first line contains a single integer, n, denoting the number of orders.
    Each of the n subsequent lines contains two space-separated integers describing the respective values of ti and di for order i.

    Constraints
    1 <= n<= 10^3
    1 <= i<= n
    1 <= ti, di <=10^6
    Output Format

    Print a single line of n space-separated order numbers (recall that orders are numbered from 1 to n ) describing the sequence in which the customers receive their burgers. If two or more customers receive their burgers at the same time, print the smallest order number first.
  • Test Case 1
    Input (stdin)3
    1 3
    2 3
    3 3
    Expected Output1 2 3
  • Test Case 2
    Input (stdin)5
    8 1
    4 2
    5 6
    3 1
    4 3
    Expected Output4 2 5 1 3

No comments:

Post a Comment

Question Name:TOWER OF HANOI

#include < bits / stdc ++. h > #define lli long long using namespace std ; lli dp [ 202 ]; int main () { int t , n ; ...