×

CL16BD - Editorial

Author: Subham Das
Tester: Soumik Sarkar
Editorialist: Subham Das

EASY

Array, Sorting

PROBLEM:

Given two integer arrays C and D both of length N, establish a one-to-one correspondence between the elements of C and D so as to maximize the number of pairings where the element of C is greater than the element from D in a pair.

EXPLANATION

The value of n and the array C, D which contains the power of Chef's cards and Devu's cards respectively are given within every test case. The first step would be to sort the array C and D in increasing order. Then number of times Chef's cards have more value than Devu's cards can be found out with the help of the following greedy algorithm:

j = 0;
for i  0 to n-1
if(C[i] > D[j])
j = j+1;

After this printing the value of j would yield the answer as (j-1) is the maximum value upto which all values of array D are lesser than some corresponding value in array C.

Complexity: $\mathcal{O}(N\, log\, N)$

AUTHOR'S AND TESTER'S SOLUTIONS:

Author's solution can be found here.
Tester's solution can be found here.

This question is marked "community wiki".

6★meooow ♦
7.3k720
accept rate: 48%

19.8k350498541

 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×15,852
×3,820
×1,024
×801
×18
×1

question asked: 14 Oct '16, 23:11

question was seen: 568 times

last updated: 07 Jun '17, 17:30