Knowee
Questions
Features
Study Tools

Ranking BooksMax Score: 100There are N books in a shelf which are already arranged in non-increasing order of number of pages in the books. Each book will be given a rank starting from 1 depending on the number of pages. The book with the highest number of pages will be ranked 1. You are writing a new book and it will be completed in M days. Everyday after adding some pages in your book, you want to find the rank of the book in the shelf. Please note that book's with same number of pages will be given same rank. Write an algorithm to find the rank of your book in the shelf for each of the M days.Input FormatFirst line of input contains T - number of test cases. Its followed by 4T lines, the first line contains N - number of books in the shelf and the second line contains N integers, which denotes the number of pages in ith book. The third line contains M - number of days to complete your new book and the fourth line contains M integers, which denotes the number of pages in your new book at the end of ith day.Output FormatFor each testcase, print M integers denoting the rank of your book at the end of each of the M days, separated by a new line.Constraints30 points1 <= T <= 1001 <= N, M <= 1021 <= arr[i] <= 10670 points1 <= T <= 2001 <= N, M <= 1041 <= arr[i] <= 106ExampleInput27100 100 50 40 40 20 1045 25 50 120345 30 1245 12 70 100Output6 4 2 14 3 1 1ExplanationExample 1:When your book has 5 pages, it will be ranked 6: 100 100 50 40 40 20 10 "5"When your book has 25 pages, it will be ranked 4: 100 100 50 40 40 "25" 20 10When your book has 50 pages, it will be ranked 2: 100 100 50 "50" 40 40 20 10When your book has 120 pages, it will be ranked 1: "120" 100 100 50 40 40 20 10

Question

Ranking BooksMax Score: 100There are N books in a shelf which are already arranged in non-increasing order of number of pages in the books. Each book will be given a rank starting from 1 depending on the number of pages. The book with the highest number of pages will be ranked 1. You are writing a new book and it will be completed in M days. Everyday after adding some pages in your book, you want to find the rank of the book in the shelf. Please note that book's with same number of pages will be given same rank. Write an algorithm to find the rank of your book in the shelf for each of the M days.Input FormatFirst line of input contains T - number of test cases. Its followed by 4T lines, the first line contains N - number of books in the shelf and the second line contains N integers, which denotes the number of pages in ith book. The third line contains M - number of days to complete your new book and the fourth line contains M integers, which denotes the number of pages in your new book at the end of ith day.Output FormatFor each testcase, print M integers denoting the rank of your book at the end of each of the M days, separated by a new line.Constraints30 points1 <= T <= 1001 <= N, M <= 1021 <= arr[i] <= 10670 points1 <= T <= 2001 <= N, M <= 1041 <= arr[i] <= 106ExampleInput27100 100 50 40 40 20 1045 25 50 120345 30 1245 12 70 100Output6 4 2 14 3 1 1ExplanationExample 1:When your book has 5 pages, it will be ranked 6: 100 100 50 40 40 20 10 "5"When your book has 25 pages, it will be ranked 4: 100 100 50 40 40 "25" 20 10When your book has 50 pages, it will be ranked 2: 100 100 50 "50" 40 40 20 10When your book has 120 pages, it will be ranked 1: "120" 100 100 50 40 40 20 10

...expand
🧐 Not the exact question you are looking for?Go ask a question

Solution

This problem is a competitive programming problem. Here's a step-by-step guide on how to solve it:

Step 1: Understand the problem You are given a list of books, sorted in non-increasing order by the number of pages. Each day, you add some pages to your book and you want to find out the rank of your book on the shelf. Books with the same number of pages have the same rank.

Step 2: Parse the input The first line of input is the number of test cases. For each test case, you have four lines of input:

  • The first line is the number of books on the shelf.
  • The second line is a list of integers representing the number of pages in each book.
  • The third line is the number of days it takes to complete your book.
  • The fourth line is a list of integers representing the number of pages in your book at the end of each day.

Step 3: Solve the problem For each day, you need to find out the rank of your book. This can be done by comparing the number of pages in your book with the number of pages in the other books. If your book has more pages than a book, it has a higher rank. If it has the same number of pages, it has the same rank.

Step 4: Print the output For each test case, print the rank of your book at the end of each day.

Here's a Python solution for the problem:

T = int(input())
for _ in range(T):
    N = int(input())
    books = list(map(int, input().split()))
    M = int(input())
    pages = list(map(int, input().split()))
    for p in pages:
        rank = sum(b > p for b in books) + 1
        print(rank)

This solution works by counting the number of books that have more pages than your book and adding 1 to get the rank of your book.

This problem has been solved

Similar Questions

Ranking BooksThere are N books in a shelf which are already arranged in non-increasing order of number of pages in the books. Each book will be given a rank starting from 1 depending on the number of pages. The book with the highest number of pages will be ranked 1. You are writing a new book and it will be completed in M days. Everyday after adding some pages in your book, you want to find the rank of the book in the shelf. Please note that book's with same number of pages will be given same rank. Write an algorithm to find the rank of your book in the shelf for each of the M days.Input FormatFirst line of input contains T - number of test cases. Its followed by 4T lines, the first line contains N - number of books in the shelf and the second line contains N integers, which denotes the number of pages in ith book. The third line contains M - number of days to complete your new book and the fourth line contains M integers, which denotes the number of pages in your new book at the end of ith day.Output FormatFor each testcase, print M integers denoting the rank of your book at the end of each of the M days, separated by a new line.Constraints30 points1 <= T <= 1001 <= N, M <= 1021 <= arr[i] <= 10670 points1 <= T <= 2001 <= N, M <= 1041 <= arr[i] <= 106ExampleInput27100 100 50 40 40 20 1045 25 50 120345 30 1245 12 70 100Output6 4 2 14 3 1 1ExplanationExample 1:When your book has 5 pages, it will be ranked 6: 100 100 50 40 40 20 10 "5"When your book has 25 pages, it will be ranked 4: 100 100 50 40 40 "25" 20 10When your book has 50 pages, it will be ranked 2: 100 100 50 "50" 40 40 20 10When your book has 120 pages, it will be ranked 1: "120" 100 100 50 40 40 20 10

In a book, the page numbers are given in form a, b, b, c, c, c,….find the alphabet written on the 100th page of the book. N

The total number of digits used to number a 200 page book is:

In the page rank algorithm the leader is decided by? A node(person) with maximum number of outgoing edges. A node(person) with maximum number of incoming edges. A node(person) which is visited maximum times. Can not decide.

| Number of Books | Frequency ||------------------|-----------|| 0-5 | 6 || 6-10 | 12 || 11-15 | 8 || 16-20 | 5 || 21-25 | 3 |

1/1

Upgrade your grade with Knowee

Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.