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

×

NZEC using comparator but AC using comparable interface

I got ac using Comparable interface which I used for sorting but using comparator I was getting NZEC. Why so? Please help me out!!!!!!!!!!!!!!! here is my code using comparable interface https://www.codechef.com/viewsolution/14641628 here is my code using comparator interface https://www.codechef.com/viewsolution/14641516 Question is Stable Market from April Long challenge

asked 23 Jul '17, 01:06

kunal12's gravatar image

3★kunal12
445
accept rate: 0%

edited 23 Jul '17, 01:12


The comparisons in the two solutions are not the same. Here is your solution that gets AC using the Comparator, I have not changed anything other than the compare function.
Helpful tip: Use lambda expressions to reduce the amount of code you need to write for a custom Comparator. Your array can be sorted easily using the code

Arrays.sort(query, (s1, s2) -> {
    int block_size1 = SMarketBC.block_size;
    if(s1.l/block_size1 == s2.l/block_size1)
        return s1.r - s2.r;
    else
        return s1.l/block_size1 - s2.l/block_size1;
});

link

answered 23 Jul '17, 01:31

meooow's gravatar image

6★meooow ♦
7.3k720
accept rate: 48%

Thanks Alot!! now I got it. Thankyou for the tip also!!!!

link

answered 23 Jul '17, 02:10

kunal12's gravatar image

3★kunal12
445
accept rate: 0%

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:

×124
×10

question asked: 23 Jul '17, 01:06

question was seen: 218 times

last updated: 23 Jul '17, 02:10