You are not logged in. Please login at www.codechef.com to post your questions!

×

CL16BD - Editorial

PROBLEM LINK:

Practice
Contest

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

DIFFICULTY:

EASY

PREREQUISITES:

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".

asked 14 Oct '16, 23:11

meooow's gravatar image

6★meooow ♦
7.3k720
accept rate: 48%

edited 07 Jun '17, 17:30

admin's gravatar image

0★admin ♦♦
19.8k350498541

toggle preview
Preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • 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