Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8643609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T12:05:31+00:00 2026-06-12T12:05:31+00:00

I am trying out this problem in codechef – http://www.codechef.com/OCT12/problems/DRGNBOOL This is my solution

  • 0

I am trying out this problem in codechef – http://www.codechef.com/OCT12/problems/DRGNBOOL

This is my solution

def array_sum(a)
    sum=0
    a.each do |x|
        sum=sum+x
    end
    return sum
end

number_of_test_cases=gets.to_i
number_of_test_cases.times do
    n_and_m=gets.split(" ")
    n=n_and_m[0].to_i
    m=n_and_m[1].to_i
    soints=Hash.new{|h, k| h[k]=[]}
    sofloats=Hash.new{|h, k| h[k]=[]}

    n.times do
        x=gets.split(" ")
        a=x.first.to_i
        b=x.last
        soints[b].push(a)
    end
    m.times do
        x=gets.split(" ")
        a=x.first.to_i
        b=x.last
        sofloats[b].push(a)
    end

    result=0
    soints.each_pair do |k, v|
        if v.size>1
            max_value=sofloats[k].max
            v.each do |val|
                if val<max_value
                    result=result+(max_value-val)
                    val=max_value
                end
            end
        end
        l=array_sum(v)
        k=array_sum(sofloats[k])
        if l<k
            result=result+(k-l)
        end
    end
    puts result
end

I am getting “Wrong answer” on submission. My solution works for the given cases. Can anybody provide me test cases where my solution fails?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T12:05:33+00:00Added an answer on June 12, 2026 at 12:05 pm

    Edit: I found a case where you code fails.

    1
    2 1
    10 1   
    10 1
    50 1
    110 # => the right answer is 30
    

    in case, here is an answer I wrote which got accepted.

    def get_ints
      gets.chomp.split.map(&:to_i)
    end
    
    def gather_warriors(count, hash)
      count.times do
        power, level = get_ints
        (hash[level] ||= []) << power
      end
    end
    
    test_cases_count = gets.chomp.to_i
    test_cases = []
    
    test_cases_count.times do
      soints = {}
      sofloats = {}
      soints_count, sofloats_count = get_ints
    
      gather_warriors(soints_count, soints)
      gather_warriors(sofloats_count, sofloats)
    
      test_cases << [soints, sofloats]
    end
    
    def run_test(soints, sofloats)
      needed_chakra = 0
    
      soints.keys.each do |level|
        soints_summed_power = soints[level].inject(&:+)
        sofloats_summed_power = sofloats[level].inject(&:+)
    
        needed_chakra += [0, sofloats_summed_power - soints_summed_power].max
      end
    
      puts needed_chakra
    end
    
    test_cases.each do |test_case|
      run_test(test_case.first, test_case.last)
    end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

http://www.hanselman.com/blog/MixMobileWebSitesWithASPNETMVCAndTheMobileBrowserDefinitionFile.aspx To the sake of simplicity, please try out this. Basically, I am trying
I've been trying to figure out a solution to this problem but haven't been
So we have this problem that we are trying to figure out. Heres what
I have been trying to figure out why I am getting this problem and
I've been pulling out my hair trying to figure this problem out. I have
I can't seem to figure out this problem. I am trying to get xml
I'm trying to figure out this problem for one of my comp sci classes,
I have two websites http://www.buywwetickets.com/ http://www.ufcticketbooth.com/ The problem is that sometimes before the websites
I have been trying to figure out this problem for a while now and
I've been trying to work out this particular problem and though I can easily

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.