Rick is really fond of fruit juices, but he is bored of their traditional flavours. Therefore, he has decided to mix as many of them as possible to obtain something entirely new as a result.
He has N glasses, numbered from 0 to N-1, each containing a different kind of juice. The J-th glass has capacity[J] units of capacity and contains juice[J] units of juice. In each glass there is at least one unit of juice.
Rick want to create a multivitamin mix in one of the glasses. He is going to do it by pouring juice from several other glasses into the chosen one. Each of the used glasses must be empty at the end (all of the juice from each glass has to be poured out).
What is the maximum number of flavours that Rick can mix?
Write a function:
def solution(juice, capacity)
that, given arrays juice and capacity, both of size N, returns the maximum number of flavours that Rick can mix in a single glass.
Examples:
1. Given juice = [10, 2, 1, 1] and capacity = [10, 3, 2, 2], your function should return 2. Rick can pour juice from the 3rd glass into the 2nd one.
2. Given juice = [1, 2, 3, 4] and capacity = [3, 6, 4, 4], your function should return 3. Rick can pour juice from the 0th and 2nd glasses into the 1st one.
3. Given juice = [2, 3] and capacity = [3, 4], your function should return 1. No matter which glass he chooses, Rick cannot pour juice from the other one into it. The maximum number of flavours in the chosen glass is 1.
4. Given juice = [1, 1, 5] and capacity = [6, 5, 8], your function should return 3. Rick can mix all juices in the 2nd glass.
Write an efficient algorithm for the following assumptions:
- N is an integer within the range [2..100,000];
- each element of arrays juice and capacity is an integer within the range [1..1,000,000,000];
- arrays juice and capacity have the same length, equal to N;
- for each J juice[J] ≤ capacity[J].
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
t[:cum] = sum
end
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
tuple.
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
tuple.each do |t|
remaining = t[:remaining]
end
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
tuple.each do |t|
remaining = t[:remaining]
tuple.each do |_t|
end
end
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each do |_t|
end
end
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
next if i == j
end
end
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
next if i == j
end
end
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
next if i == j
end
end
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
next if i == j
if _t[j][:cum] - t[i][:]
end
end
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
next if i == j
if _t[j][:cum] - t[i][:juice] <= remaining
max_mix = []
end
end
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
next if i == j
if _t[j][:cum] - t[i][:juice] <= remaining
max_mix = [j]
end
end
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
next if i == j
if _t[j][:cum] - t[i][:juice] <= remaining
max_mix = [j+1,max_mix].max
end
end
end
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
next if i == j
if _t[j][:cum] - t[i][:juice] <= remaining
max_mix = [j+1,max_mix].max
end
end
end
max_mix
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
next if i == j
if _t[j][:cum] - t[i][:juice] <= remaining
max_mix = [j+1,max_mix].max
ne
end
end
end
max_mix
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
next if i == j
if _t[j][:cum] - t[i][:juice] <= remaining
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
next if i == j
if _t[j][:cum] - t[i][:juice] <= remaining
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and
next if i == j
if _t[j][:cum] - t[i][:juice] <= remaining
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[j][:cum] - t[i][:juice] <= remaining
next if i == j
if _t[j][:cum] - t[i][:juice] <= remaining
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[j][:cum] <= remaining
next if i == j
if _t[j][:cum] - t[i][:juice] <= remaining
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[j][:cum] <= remaining
max_mix = [j+1,max_mix].max
next
end
next if i == j
if _t[j][:cum] - t[i][:juice] <= remaining
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[j][:cum] <= remaining
max_mix = [j+1,max_mix].max
next
end
next if i == j
if _t[j][:cum] - t[i][:juice] <= remaining
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
exec.rb:8:in `block in solution': undefined local variable or method `i' for main:Object (NameError) from exec.rb:7:in `each' from exec.rb:7:in `each_with_index' from exec.rb:7:in `solution' from exec.rb:152:in `<main>'
exec.rb:8:in `block in solution': undefined local variable or method `i' for main:Object (NameError) from exec.rb:7:in `each' from exec.rb:7:in `each_with_index' from exec.rb:7:in `solution' from exec.rb:152:in `<main>'
exec.rb:8:in `block in solution': undefined local variable or method `i' for main:Object (NameError) from exec.rb:7:in `each' from exec.rb:7:in `each_with_index' from exec.rb:7:in `solution' from exec.rb:152:in `<main>'
exec.rb:8:in `block in solution': undefined local variable or method `i' for main:Object (NameError) from exec.rb:7:in `each' from exec.rb:7:in `each_with_index' from exec.rb:7:in `solution' from exec.rb:152:in `<main>'
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[j][:cum] <= remaining
max_mix = [j+1,max_mix].max
next
end
next if i == j
if _t[j][:cum] - t[i][:juice] <= remaining
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[j][:cum] <= remaining
max_mix = [j+1,max_mix].max
next
end
next if i == j
if _t[j][:cum] - t[i][:juice] <= remaining
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
exec.rb:27:in `block (2 levels) in solution': undefined method `[]' for nil:NilClass (NoMethodError) from exec.rb:21:in `each' from exec.rb:21:in `each_with_index' from exec.rb:21:in `block in solution' from exec.rb:19:in `each' from exec.rb:19:in `each_with_index' from exec.rb:19:in `solution' from exec.rb:152:in `<main>'
exec.rb:27:in `block (2 levels) in solution': undefined method `[]' for nil:NilClass (NoMethodError) from exec.rb:21:in `each' from exec.rb:21:in `each_with_index' from exec.rb:21:in `block in solution' from exec.rb:19:in `each' from exec.rb:19:in `each_with_index' from exec.rb:19:in `solution' from exec.rb:152:in `<main>'
exec.rb:27:in `block (2 levels) in solution': undefined method `[]' for nil:NilClass (NoMethodError) from exec.rb:21:in `each' from exec.rb:21:in `each_with_index' from exec.rb:21:in `block in solution' from exec.rb:19:in `each' from exec.rb:19:in `each_with_index' from exec.rb:19:in `solution' from exec.rb:152:in `<main>'
exec.rb:27:in `block (2 levels) in solution': undefined method `[]' for nil:NilClass (NoMethodError) from exec.rb:21:in `each' from exec.rb:21:in `each_with_index' from exec.rb:21:in `block in solution' from exec.rb:19:in `each' from exec.rb:19:in `each_with_index' from exec.rb:19:in `solution' from exec.rb:152:in `<main>'
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[j][:cum] <= remaining
max_mix = [j+1,max_mix].max
next
end
next if i == j
if _t[j[:cum] - t[i][:juice] <= remaining
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[j][:cum] <= remaining
max_mix = [j+1,max_mix].max
next
end
next if i == j
if _t[:cum] - t[:juice] <= remaining
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[:cum] <= remaining
max_mix = [j+1,max_mix].max
next
end
next if i == j
if _t[:cum] - t[:juice] <= remaining
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
p
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[:cum] <= remaining
max_mix = [j+1,max_mix].max
next
end
next if i == j
if _t[:cum] - t[:juice] <= remaining
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[:cum] <= remaining
max_mix = [j+1,max_mix].max
next
end
next if i == j
if _t[:cum] - t[:juice] <= remaining
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
[{:juice=>1, :remaining=>1, :cum=>1}, {:juice=>1, :remaining=>1, :cum=>2}, {:juice=>2, :remaining=>1, :cum=>4}, {:juice=>10, :remaining=>0, :cum=>14}]
[{:juice=>1, :remaining=>2, :cum=>1}, {:juice=>2, :remaining=>4, :cum=>3}, {:juice=>3, :remaining=>1, :cum=>6}, {:juice=>4, :remaining=>0, :cum=>10}]
[{:juice=>2, :remaining=>1, :cum=>2}, {:juice=>3, :remaining=>1, :cum=>5}]
[{:juice=>1, :remaining=>5, :cum=>1}, {:juice=>1, :remaining=>4, :cum=>2}, {:juice=>5, :remaining=>3, :cum=>7}]
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[:cum] <= remaining
max_mix = [j+1,max_mix].max
next
end
next if i == j
if _t[:cum] - t[:juice] <= remaining
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[:cum] <= remaining
puts ""
max_mix = [j+1,max_mix].max
next
end
next if i == j
if _t[:cum] - t[:juice] <= remaining
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[:cum] <= remaining
puts "#{} #{}"
max_mix = [j+1,max_mix].max
next
end
next if i == j
if _t[:cum] - t[:juice] <= remaining
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[:cum] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
next if i == j
if _t[:cum] - t[:juice] <= remaining
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[:cum] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
next if i == j
if _t[:cum] - t[:juice] <= remaining
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[:cum] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
next if i == j
if _t[:cum] - t[:juice] <= remaining
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[:cum] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
next if i == j
if _t[:cum] - t[:juice] <= remaining
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[:cum] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
next if i == j
if _t[:cum] - t[:juice] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
[{:juice=>1, :remaining=>1, :cum=>1}, {:juice=>1, :remaining=>1, :cum=>2}, {:juice=>2, :remaining=>1, :cum=>4}, {:juice=>10, :remaining=>0, :cum=>14}] 1 {:juice=>1, :remaining=>1, :cum=>2} - 0 {:juice=>1, :remaining=>1, :cum=>1} 2 {:juice=>2, :remaining=>1, :cum=>4} - 0 {:juice=>1, :remaining=>1, :cum=>1}
[{:juice=>1, :remaining=>2, :cum=>1}, {:juice=>2, :remaining=>4, :cum=>3}, {:juice=>3, :remaining=>1, :cum=>6}, {:juice=>4, :remaining=>0, :cum=>10}] 1 {:juice=>2, :remaining=>4, :cum=>3} - 0 {:juice=>1, :remaining=>2, :cum=>1} 2 {:juice=>3, :remaining=>1, :cum=>6} - 0 {:juice=>1, :remaining=>2, :cum=>1}
[{:juice=>2, :remaining=>1, :cum=>2}, {:juice=>3, :remaining=>1, :cum=>5}]
[{:juice=>1, :remaining=>5, :cum=>1}, {:juice=>1, :remaining=>4, :cum=>2}, {:juice=>5, :remaining=>3, :cum=>7}] 1 {:juice=>1, :remaining=>4, :cum=>2} - 0 {:juice=>1, :remaining=>5, :cum=>1} 2 {:juice=>5, :remaining=>3, :cum=>7} - 0 {:juice=>1, :remaining=>5, :cum=>1} 2 {:juice=>5, :remaining=>3, :cum=>7} - 1 {:juice=>1, :remaining=>4, :cum=>2}
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[:cum] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
next if i == j
if _t[:cum] - t[:juice] <= remaining
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[:cum] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+2,max_mix].max
next
end
next if i == j
if _t[:cum] - t[:juice] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[:cum] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
next if i == j
if _t[:cum] - t[:juice] <= remaining
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[:cum] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+2,max_mix].max
next
end
next if i == j
if _t[:cum] - t[:juice] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
[{:juice=>1, :remaining=>1, :cum=>1}, {:juice=>1, :remaining=>1, :cum=>2}, {:juice=>2, :remaining=>1, :cum=>4}, {:juice=>10, :remaining=>0, :cum=>14}] 1 {:juice=>1, :remaining=>1, :cum=>2} - 0 {:juice=>1, :remaining=>1, :cum=>1} 2 {:juice=>2, :remaining=>1, :cum=>4} - 0 {:juice=>1, :remaining=>1, :cum=>1}
[{:juice=>1, :remaining=>2, :cum=>1}, {:juice=>2, :remaining=>4, :cum=>3}, {:juice=>3, :remaining=>1, :cum=>6}, {:juice=>4, :remaining=>0, :cum=>10}] 1 {:juice=>2, :remaining=>4, :cum=>3} - 0 {:juice=>1, :remaining=>2, :cum=>1} 2 {:juice=>3, :remaining=>1, :cum=>6} - 0 {:juice=>1, :remaining=>2, :cum=>1}
[{:juice=>2, :remaining=>1, :cum=>2}, {:juice=>3, :remaining=>1, :cum=>5}]
[{:juice=>1, :remaining=>5, :cum=>1}, {:juice=>1, :remaining=>4, :cum=>2}, {:juice=>5, :remaining=>3, :cum=>7}] 1 {:juice=>1, :remaining=>4, :cum=>2} - 0 {:juice=>1, :remaining=>5, :cum=>1} 2 {:juice=>5, :remaining=>3, :cum=>7} - 0 {:juice=>1, :remaining=>5, :cum=>1} 2 {:juice=>5, :remaining=>3, :cum=>7} - 1 {:juice=>1, :remaining=>4, :cum=>2}
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[:cum] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
next if i == j
if _t[:cum] - t[:juice] <= remaining
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[:cum] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+2,max_mix].max
next
end
if _t[:cum] - t[:juice] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[:cum] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
next if i == j
if _t[:cum] - t[:juice] <= remaining
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[:cum] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+2,max_mix].max
next
end
if _t[:cum] - t[:juice] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
[{:juice=>1, :remaining=>1, :cum=>1}, {:juice=>1, :remaining=>1, :cum=>2}, {:juice=>2, :remaining=>1, :cum=>4}, {:juice=>10, :remaining=>0, :cum=>14}] 1 {:juice=>1, :remaining=>1, :cum=>2} - 0 {:juice=>1, :remaining=>1, :cum=>1} 2 {:juice=>2, :remaining=>1, :cum=>4} - 0 {:juice=>1, :remaining=>1, :cum=>1}
[{:juice=>1, :remaining=>2, :cum=>1}, {:juice=>2, :remaining=>4, :cum=>3}, {:juice=>3, :remaining=>1, :cum=>6}, {:juice=>4, :remaining=>0, :cum=>10}] 1 {:juice=>2, :remaining=>4, :cum=>3} - 0 {:juice=>1, :remaining=>2, :cum=>1} 2 {:juice=>3, :remaining=>1, :cum=>6} - 0 {:juice=>1, :remaining=>2, :cum=>1}
[{:juice=>2, :remaining=>1, :cum=>2}, {:juice=>3, :remaining=>1, :cum=>5}]
[{:juice=>1, :remaining=>5, :cum=>1}, {:juice=>1, :remaining=>4, :cum=>2}, {:juice=>5, :remaining=>3, :cum=>7}] 1 {:juice=>1, :remaining=>4, :cum=>2} - 0 {:juice=>1, :remaining=>5, :cum=>1} 2 {:juice=>5, :remaining=>3, :cum=>7} - 0 {:juice=>1, :remaining=>5, :cum=>1} 2 {:juice=>5, :remaining=>3, :cum=>7} - 1 {:juice=>1, :remaining=>4, :cum=>2}
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[:cum] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
next if i == j
if _t[:cum] - t[:juice] <= remaining
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[:cum] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+2,max_mix].max
next
end
if _t[:cum] - t[:juice] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
[{:juice=>1, :remaining=>1, :cum=>1}, {:juice=>1, :remaining=>1, :cum=>2}, {:juice=>2, :remaining=>1, :cum=>4}, {:juice=>10, :remaining=>0, :cum=>14}] 1 {:juice=>1, :remaining=>1, :cum=>2} - 0 {:juice=>1, :remaining=>1, :cum=>1} 2 {:juice=>2, :remaining=>1, :cum=>4} - 0 {:juice=>1, :remaining=>1, :cum=>1}
[{:juice=>1, :remaining=>2, :cum=>1}, {:juice=>2, :remaining=>4, :cum=>3}, {:juice=>3, :remaining=>1, :cum=>6}, {:juice=>4, :remaining=>0, :cum=>10}] 1 {:juice=>2, :remaining=>4, :cum=>3} - 0 {:juice=>1, :remaining=>2, :cum=>1} 2 {:juice=>3, :remaining=>1, :cum=>6} - 0 {:juice=>1, :remaining=>2, :cum=>1}
[{:juice=>2, :remaining=>1, :cum=>2}, {:juice=>3, :remaining=>1, :cum=>5}]
[{:juice=>1, :remaining=>5, :cum=>1}, {:juice=>1, :remaining=>4, :cum=>2}, {:juice=>5, :remaining=>3, :cum=>7}] 1 {:juice=>1, :remaining=>4, :cum=>2} - 0 {:juice=>1, :remaining=>5, :cum=>1} 2 {:juice=>5, :remaining=>3, :cum=>7} - 0 {:juice=>1, :remaining=>5, :cum=>1} 2 {:juice=>5, :remaining=>3, :cum=>7} - 1 {:juice=>1, :remaining=>4, :cum=>2}
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[:cum] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
next if i == j
if _t[:cum] - t[:juice] <= remaining
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[:cum] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+2,max_mix].max
next
end
if _t[:cum] - t[:juice] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[:cum] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
next if i == j
if _t[:cum] - t[:juice] <= remaining
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[:cum] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+2,max_mix].max
next
end
if _t[:cum] - t[:juice] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
puts "Exiting"
puts "#{i} #{t} - #{j} #{_t}"
break
end
end
max_mix
end
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
[{:juice=>1, :remaining=>1, :cum=>1}, {:juice=>1, :remaining=>1, :cum=>2}, {:juice=>2, :remaining=>1, :cum=>4}, {:juice=>10, :remaining=>0, :cum=>14}] 1 {:juice=>1, :remaining=>1, :cum=>2} - 0 {:juice=>1, :remaining=>1, :cum=>1} 2 {:juice=>2, :remaining=>1, :cum=>4} - 0 {:juice=>1, :remaining=>1, :cum=>1}
[{:juice=>1, :remaining=>2, :cum=>1}, {:juice=>2, :remaining=>4, :cum=>3}, {:juice=>3, :remaining=>1, :cum=>6}, {:juice=>4, :remaining=>0, :cum=>10}] 1 {:juice=>2, :remaining=>4, :cum=>3} - 0 {:juice=>1, :remaining=>2, :cum=>1} 2 {:juice=>3, :remaining=>1, :cum=>6} - 0 {:juice=>1, :remaining=>2, :cum=>1}
[{:juice=>2, :remaining=>1, :cum=>2}, {:juice=>3, :remaining=>1, :cum=>5}]
[{:juice=>1, :remaining=>5, :cum=>1}, {:juice=>1, :remaining=>4, :cum=>2}, {:juice=>5, :remaining=>3, :cum=>7}] 1 {:juice=>1, :remaining=>4, :cum=>2} - 0 {:juice=>1, :remaining=>5, :cum=>1} 2 {:juice=>5, :remaining=>3, :cum=>7} - 0 {:juice=>1, :remaining=>5, :cum=>1} 2 {:juice=>5, :remaining=>3, :cum=>7} - 1 {:juice=>1, :remaining=>4, :cum=>2}
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[:cum] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
next if i == j
if _t[:cum] - t[:juice] <= remaining
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[:cum] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+2,max_mix].max
next
end
if _t[:cum] - t[:juice] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
puts "Exiting"
puts "#{i} #{t} - #{j} #{_t}"
break
end
end
max_mix
end
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[:cum] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
next if i == j
if _t[:cum] - t[:juice] <= remaining
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
puts "#{i} #{j}"
if j < i and _t[:cum] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+2,max_mix].max
next
end
if _t[:cum] - t[:juice] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
puts "Exiting"
puts "#{i} #{t} - #{j} #{_t}"
break
end
end
max_mix
end
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[:cum] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
next if i == j
if _t[:cum] - t[:juice] <= remaining
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
puts "#{i} #{j}"
if j < i and _t[:cum] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+2,max_mix].max
next
end
if _t[:cum] - t[:juice] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
puts "Exiting"
puts "#{i} #{t} - #{j} #{_t}"
break
end
end
max_mix
end
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
[{:juice=>1, :remaining=>1, :cum=>1}, {:juice=>1, :remaining=>1, :cum=>2}, {:juice=>2, :remaining=>1, :cum=>4}, {:juice=>10, :remaining=>0, :cum=>14}] 1 {:juice=>1, :remaining=>1, :cum=>2} - 0 {:juice=>1, :remaining=>1, :cum=>1} 2 {:juice=>2, :remaining=>1, :cum=>4} - 0 {:juice=>1, :remaining=>1, :cum=>1}
[{:juice=>1, :remaining=>2, :cum=>1}, {:juice=>2, :remaining=>4, :cum=>3}, {:juice=>3, :remaining=>1, :cum=>6}, {:juice=>4, :remaining=>0, :cum=>10}] 1 {:juice=>2, :remaining=>4, :cum=>3} - 0 {:juice=>1, :remaining=>2, :cum=>1} 2 {:juice=>3, :remaining=>1, :cum=>6} - 0 {:juice=>1, :remaining=>2, :cum=>1}
[{:juice=>2, :remaining=>1, :cum=>2}, {:juice=>3, :remaining=>1, :cum=>5}]
[{:juice=>1, :remaining=>5, :cum=>1}, {:juice=>1, :remaining=>4, :cum=>2}, {:juice=>5, :remaining=>3, :cum=>7}] 1 {:juice=>1, :remaining=>4, :cum=>2} - 0 {:juice=>1, :remaining=>5, :cum=>1} 2 {:juice=>5, :remaining=>3, :cum=>7} - 0 {:juice=>1, :remaining=>5, :cum=>1} 2 {:juice=>5, :remaining=>3, :cum=>7} - 1 {:juice=>1, :remaining=>4, :cum=>2}
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[:cum] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
next if i == j
if _t[:cum] - t[:juice] <= remaining
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
puts "#{i} #{j}"
if j < i and _t[:cum] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+2,max_mix].max
next
end
if _t[:cum] - t[:juice] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
puts "Exiting"
puts "#{i} #{t} - #{j} #{_t}"
break
end
end
max_mix
end
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
[{:juice=>1, :remaining=>1, :cum=>1}, {:juice=>1, :remaining=>1, :cum=>2}, {:juice=>2, :remaining=>1, :cum=>4}, {:juice=>10, :remaining=>0, :cum=>14}] 1 {:juice=>1, :remaining=>1, :cum=>2} - 0 {:juice=>1, :remaining=>1, :cum=>1} 2 {:juice=>2, :remaining=>1, :cum=>4} - 0 {:juice=>1, :remaining=>1, :cum=>1}
[{:juice=>1, :remaining=>2, :cum=>1}, {:juice=>2, :remaining=>4, :cum=>3}, {:juice=>3, :remaining=>1, :cum=>6}, {:juice=>4, :remaining=>0, :cum=>10}] 1 {:juice=>2, :remaining=>4, :cum=>3} - 0 {:juice=>1, :remaining=>2, :cum=>1} 2 {:juice=>3, :remaining=>1, :cum=>6} - 0 {:juice=>1, :remaining=>2, :cum=>1}
[{:juice=>2, :remaining=>1, :cum=>2}, {:juice=>3, :remaining=>1, :cum=>5}]
[{:juice=>1, :remaining=>5, :cum=>1}, {:juice=>1, :remaining=>4, :cum=>2}, {:juice=>5, :remaining=>3, :cum=>7}] 1 {:juice=>1, :remaining=>4, :cum=>2} - 0 {:juice=>1, :remaining=>5, :cum=>1} 2 {:juice=>5, :remaining=>3, :cum=>7} - 0 {:juice=>1, :remaining=>5, :cum=>1} 2 {:juice=>5, :remaining=>3, :cum=>7} - 1 {:juice=>1, :remaining=>4, :cum=>2}
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[:cum] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
next if i == j
if _t[:cum] - t[:juice] <= remaining
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
puts "#{i} #{j}"
if j < i and _t[:cum] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+2,max_mix].max
next
end
if _t[:cum] - t[:juice] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
puts "Exiting"
puts "#{i} #{t} - #{j} #{_t}"
break
end
end
max_mix
end
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[:cum] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
next if i == j
if _t[:cum] - t[:juice] <= remaining
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
puts "here"
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
puts "#{i} #{j}"
puts "here"
if j < i and _t[:cum] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+2,max_mix].max
next
end
if _t[:cum] - t[:juice] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
puts "Exiting"
puts "#{i} #{t} - #{j} #{_t}"
break
end
end
max_mix
end
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
[{:juice=>1, :remaining=>1, :cum=>1}, {:juice=>1, :remaining=>1, :cum=>2}, {:juice=>2, :remaining=>1, :cum=>4}, {:juice=>10, :remaining=>0, :cum=>14}] 1 {:juice=>1, :remaining=>1, :cum=>2} - 0 {:juice=>1, :remaining=>1, :cum=>1} 2 {:juice=>2, :remaining=>1, :cum=>4} - 0 {:juice=>1, :remaining=>1, :cum=>1}
[{:juice=>1, :remaining=>2, :cum=>1}, {:juice=>2, :remaining=>4, :cum=>3}, {:juice=>3, :remaining=>1, :cum=>6}, {:juice=>4, :remaining=>0, :cum=>10}] 1 {:juice=>2, :remaining=>4, :cum=>3} - 0 {:juice=>1, :remaining=>2, :cum=>1} 2 {:juice=>3, :remaining=>1, :cum=>6} - 0 {:juice=>1, :remaining=>2, :cum=>1}
[{:juice=>2, :remaining=>1, :cum=>2}, {:juice=>3, :remaining=>1, :cum=>5}]
[{:juice=>1, :remaining=>5, :cum=>1}, {:juice=>1, :remaining=>4, :cum=>2}, {:juice=>5, :remaining=>3, :cum=>7}] 1 {:juice=>1, :remaining=>4, :cum=>2} - 0 {:juice=>1, :remaining=>5, :cum=>1} 2 {:juice=>5, :remaining=>3, :cum=>7} - 0 {:juice=>1, :remaining=>5, :cum=>1} 2 {:juice=>5, :remaining=>3, :cum=>7} - 1 {:juice=>1, :remaining=>4, :cum=>2}
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[:cum] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
next if i == j
if _t[:cum] - t[:juice] <= remaining
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
puts "here"
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
puts "#{i} #{j}"
puts "here"
if j < i and _t[:cum] <= remaining
#puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+2,max_mix].max
next
end
if _t[:cum] - t[:juice] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
puts "Exiting"
puts "#{i} #{t} - #{j} #{_t}"
break
end
end
max_mix
end
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[:cum] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
next if i == j
if _t[:cum] - t[:juice] <= remaining
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
puts "here"
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
puts "#{i} #{j}"
puts "here"
if j < i and _t[:cum] <= remaining
#puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+2,max_mix].max
next
end
if _t[:cum] - t[:juice] <= remaining
#puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
#puts "Exiting"
#puts "#{i} #{t} - #{j} #{_t}"
break
end
end
max_mix
end
max_mix = [j+1,max_mix].max
next
end
break
end
end
max_mix
end
[{:juice=>1, :remaining=>1, :cum=>1}, {:juice=>1, :remaining=>1, :cum=>2}, {:juice=>2, :remaining=>1, :cum=>4}, {:juice=>10, :remaining=>0, :cum=>14}] 1 {:juice=>1, :remaining=>1, :cum=>2} - 0 {:juice=>1, :remaining=>1, :cum=>1} 2 {:juice=>2, :remaining=>1, :cum=>4} - 0 {:juice=>1, :remaining=>1, :cum=>1}
[{:juice=>1, :remaining=>2, :cum=>1}, {:juice=>2, :remaining=>4, :cum=>3}, {:juice=>3, :remaining=>1, :cum=>6}, {:juice=>4, :remaining=>0, :cum=>10}] 1 {:juice=>2, :remaining=>4, :cum=>3} - 0 {:juice=>1, :remaining=>2, :cum=>1} 2 {:juice=>3, :remaining=>1, :cum=>6} - 0 {:juice=>1, :remaining=>2, :cum=>1}
[{:juice=>2, :remaining=>1, :cum=>2}, {:juice=>3, :remaining=>1, :cum=>5}]
[{:juice=>1, :remaining=>5, :cum=>1}, {:juice=>1, :remaining=>4, :cum=>2}, {:juice=>5, :remaining=>3, :cum=>7}] 1 {:juice=>1, :remaining=>4, :cum=>2} - 0 {:juice=>1, :remaining=>5, :cum=>1} 2 {:juice=>5, :remaining=>3, :cum=>7} - 0 {:juice=>1, :remaining=>5, :cum=>1} 2 {:juice=>5, :remaining=>3, :cum=>7} - 1 {:juice=>1, :remaining=>4, :cum=>2}
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
if j < i and _t[:cum] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
next if i == j
if _t[:cum] - t[:juice] <= remaining
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
puts "here"
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
puts "#{i} #{j}"
puts "here"
if j < i and _t[:cum] <= remaining
#puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+2,max_mix].max
next
end
if _t[:cum] - t[:juice] <= remaining
#puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
#puts "Exiting"
#puts "#{i} #{t} - #{j} #{_t}"
break
end
end
max_mix
end
exec.rb:189: syntax error, unexpected end-of-input, expecting keyword_end
exec.rb:189: syntax error, unexpected end-of-input, expecting keyword_end
exec.rb:189: syntax error, unexpected end-of-input, expecting keyword_end
exec.rb:189: syntax error, unexpected end-of-input, expecting keyword_end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
puts "here"
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
puts "#{i} #{j}"
puts "here"
if j < i and _t[:cum] <= remaining
#puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+2,max_mix].max
next
end
if _t[:cum] - t[:juice] <= remaining
#puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
#puts "Exiting"
#puts "#{i} #{t} - #{j} #{_t}"
break
end
end
max_mix
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
puts "here"
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
puts "#{i} #{j}"
puts "here"
if j < i and _t[:cum] <= remaining
#puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+2,max_mix].max
next
end
if _t[:cum] - t[:juice] <= remaining
#puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
#puts "Exiting"
#puts "#{i} #{t} - #{j} #{_t}"
break
end
end
max_mix
end
[{:juice=>1, :remaining=>1, :cum=>1}, {:juice=>1, :remaining=>1, :cum=>2}, {:juice=>2, :remaining=>1, :cum=>4}, {:juice=>10, :remaining=>0, :cum=>14}] here 0 0 here 0 1 here 0 2 here here 1 0 here 1 1 here 1 2 here here 2 0 here 2 1 here 2 2 here here 3 0 here 3 1 here 3 2 here 3 3 here
[{:juice=>1, :remaining=>2, :cum=>1}, {:juice=>2, :remaining=>4, :cum=>3}, {:juice=>3, :remaining=>1, :cum=>6}, {:juice=>4, :remaining=>0, :cum=>10}] here 0 0 here 0 1 here 0 2 here here 1 0 here 1 1 here 1 2 here 1 3 here here 2 0 here 2 1 here 2 2 here here 3 0 here 3 1 here 3 2 here
[{:juice=>2, :remaining=>1, :cum=>2}, {:juice=>3, :remaining=>1, :cum=>5}] here 0 0 here 0 1 here here 1 0 here 1 1 here
[{:juice=>1, :remaining=>5, :cum=>1}, {:juice=>1, :remaining=>4, :cum=>2}, {:juice=>5, :remaining=>3, :cum=>7}] here 0 0 here 0 1 here 0 2 here here 1 0 here 1 1 here 1 2 here here 2 0 here 2 1 here 2 2 here
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
#puts "here"
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
#puts "#{i} #{j}"
#puts "here"
if j < i and _t[:cum] <= remaining
#puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+2,max_mix].max
next
end
if _t[:cum] - t[:juice] <= remaining
#puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
#puts "Exiting"
#puts "#{i} #{t} - #{j} #{_t}"
break
end
end
max_mix
end
[{:juice=>1, :remaining=>1, :cum=>1}, {:juice=>1, :remaining=>1, :cum=>2}, {:juice=>2, :remaining=>1, :cum=>4}, {:juice=>10, :remaining=>0, :cum=>14}]
[{:juice=>1, :remaining=>2, :cum=>1}, {:juice=>2, :remaining=>4, :cum=>3}, {:juice=>3, :remaining=>1, :cum=>6}, {:juice=>4, :remaining=>0, :cum=>10}]
[{:juice=>2, :remaining=>1, :cum=>2}, {:juice=>3, :remaining=>1, :cum=>5}]
[{:juice=>1, :remaining=>5, :cum=>1}, {:juice=>1, :remaining=>4, :cum=>2}, {:juice=>5, :remaining=>3, :cum=>7}]
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
#puts "here"
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
#puts "#{i} #{j}"
#puts "here"
if j < i and _t[:cum] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+2,max_mix].max
next
end
if _t[:cum] - t[:juice] <= remaining
#puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
#puts "Exiting"
#puts "#{i} #{t} - #{j} #{_t}"
break
end
end
max_mix
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
#puts "here"
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
#puts "#{i} #{j}"
#puts "here"
if j < i and _t[:cum] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+2,max_mix].max
next
end
if _t[:cum] - t[:juice] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
puts "Exiting"
puts "#{i} #{t} - #{j} #{_t}"
break
end
end
max_mix
end
[{:juice=>1, :remaining=>1, :cum=>1}, {:juice=>1, :remaining=>1, :cum=>2}, {:juice=>2, :remaining=>1, :cum=>4}, {:juice=>10, :remaining=>0, :cum=>14}] 0 {:juice=>1, :remaining=>1, :cum=>1} - 0 {:juice=>1, :remaining=>1, :cum=>1} 0 {:juice=>1, :remaining=>1, :cum=>1} - 1 {:juice=>1, :remaining=>1, :cum=>2} Exiting 0 {:juice=>1, :remaining=>1, :cum=>1} - 2 {:juice=>2, :remaining=>1, :cum=>4} 1 {:juice=>1, :remaining=>1, :cum=>2} - 0 {:juice=>1, :remaining=>1, :cum=>1} 1 {:juice=>1, :remaining=>1, :cum=>2} - 1 {:juice=>1, :remaining=>1, :cum=>2} Exiting 1 {:juice=>1, :remaining=>1, :cum=>2} - 2 {:juice=>2, :remaining=>1, :cum=>4} 2 {:juice=>2, :remaining=>1, :cum=>4} - 0 {:juice=>1, :remaining=>1, :cum=>1} 2 {:juice=>2, :remaining=>1, :cum=>4} - 1 {:juice=>1, :remaining=>1, :cum=>2} Exiting 2 {:juice=>2, :remaining=>1, :cum=>4} - 2 {:juice=>2, :remaining=>1, :cum=>4} 3 {:juice=>10, :remaining=>0, :cum=>14} - 0 {:juice=>1, :remaining=>1, :cum=>1} 3 {:juice=>10, :remaining=>0, :cum=>14} - 1 {:juice=>1, :remaining=>1, :cum=>2} 3 {:juice=>10, :remaining=>0, :cum=>14} - 2 {:juice=>2, :remaining=>1, :cum=>4} Exiting 3 {:juice=>10, :remaining=>0, :cum=>14} - 3 {:juice=>10, :remaining=>0, :cum=>14}
[{:juice=>1, :remaining=>2, :cum=>1}, {:juice=>2, :remaining=>4, :cum=>3}, {:juice=>3, :remaining=>1, :cum=>6}, {:juice=>4, :remaining=>0, :cum=>10}] 0 {:juice=>1, :remaining=>2, :cum=>1} - 0 {:juice=>1, :remaining=>2, :cum=>1} 0 {:juice=>1, :remaining=>2, :cum=>1} - 1 {:juice=>2, :remaining=>4, :cum=>3} Exiting 0 {:juice=>1, :remaining=>2, :cum=>1} - 2 {:juice=>3, :remaining=>1, :cum=>6} 1 {:juice=>2, :remaining=>4, :cum=>3} - 0 {:juice=>1, :remaining=>2, :cum=>1} 1 {:juice=>2, :remaining=>4, :cum=>3} - 1 {:juice=>2, :remaining=>4, :cum=>3} 1 {:juice=>2, :remaining=>4, :cum=>3} - 2 {:juice=>3, :remaining=>1, :cum=>6} Exiting 1 {:juice=>2, :remaining=>4, :cum=>3} - 3 {:juice=>4, :remaining=>0, :cum=>10} 2 {:juice=>3, :remaining=>1, :cum=>6} - 0 {:juice=>1, :remaining=>2, :cum=>1} 2 {:juice=>3, :remaining=>1, :cum=>6} - 1 {:juice=>2, :remaining=>4, :cum=>3} Exiting 2 {:juice=>3, :remaining=>1, :cum=>6} - 2 {:juice=>3, :remaining=>1, :cum=>6} 3 {:juice=>4, :remaining=>0, :cum=>10} - 0 {:juice=>1, :remaining=>2, :cum=>1} 3 {:juice=>4, :remaining=>0, :cum=>10} - 1 {:juice=>2, :remaining=>4, :cum=>3} Exiting 3 {:juice=>4, :remaining=>0, :cum=>10} - 2 {:juice=>3, :remaining=>1, :cum=>6}
[{:juice=>2, :remaining=>1, :cum=>2}, {:juice=>3, :remaining=>1, :cum=>5}] 0 {:juice=>2, :remaining=>1, :cum=>2} - 0 {:juice=>2, :remaining=>1, :cum=>2} Exiting 0 {:juice=>2, :remaining=>1, :cum=>2} - 1 {:juice=>3, :remaining=>1, :cum=>5} 1 {:juice=>3, :remaining=>1, :cum=>5} - 0 {:juice=>2, :remaining=>1, :cum=>2} Exiting 1 {:juice=>3, :remaining=>1, :cum=>5} - 1 {:juice=>3, :remaining=>1, :cum=>5}
[{:juice=>1, :remaining=>5, :cum=>1}, {:juice=>1, :remaining=>4, :cum=>2}, {:juice=>5, :remaining=>3, :cum=>7}] 0 {:juice=>1, :remaining=>5, :cum=>1} - 0 {:juice=>1, :remaining=>5, :cum=>1} 0 {:juice=>1, :remaining=>5, :cum=>1} - 1 {:juice=>1, :remaining=>4, :cum=>2} Exiting 0 {:juice=>1, :remaining=>5, :cum=>1} - 2 {:juice=>5, :remaining=>3, :cum=>7} 1 {:juice=>1, :remaining=>4, :cum=>2} - 0 {:juice=>1, :remaining=>5, :cum=>1} 1 {:juice=>1, :remaining=>4, :cum=>2} - 1 {:juice=>1, :remaining=>4, :cum=>2} Exiting 1 {:juice=>1, :remaining=>4, :cum=>2} - 2 {:juice=>5, :remaining=>3, :cum=>7} 2 {:juice=>5, :remaining=>3, :cum=>7} - 0 {:juice=>1, :remaining=>5, :cum=>1} 2 {:juice=>5, :remaining=>3, :cum=>7} - 1 {:juice=>1, :remaining=>4, :cum=>2} 2 {:juice=>5, :remaining=>3, :cum=>7} - 2 {:juice=>5, :remaining=>3, :cum=>7}
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
#puts "here"
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
#puts "#{i} #{j}"
#puts "here"
if j < i and _t[:cum] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+2,max_mix].max
next
end
if _t[:cum] - t[:juice] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
puts "Exiting"
puts #{i} #{t} - #{j} #{_t}"
break
end
end
max_mix
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
#puts "here"
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
#puts "#{i} #{j}"
#puts "here"
if j < i and _t[:cum] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+2,max_mix].max
next
end
if _t[:cum] - t[:juice] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
puts "Exiting #{i} #{t} - #{j} #{_t}"
break
end
end
max_mix
end
[{:juice=>1, :remaining=>1, :cum=>1}, {:juice=>1, :remaining=>1, :cum=>2}, {:juice=>2, :remaining=>1, :cum=>4}, {:juice=>10, :remaining=>0, :cum=>14}] 0 {:juice=>1, :remaining=>1, :cum=>1} - 0 {:juice=>1, :remaining=>1, :cum=>1} 0 {:juice=>1, :remaining=>1, :cum=>1} - 1 {:juice=>1, :remaining=>1, :cum=>2} Exiting 0 {:juice=>1, :remaining=>1, :cum=>1} - 2 {:juice=>2, :remaining=>1, :cum=>4} 1 {:juice=>1, :remaining=>1, :cum=>2} - 0 {:juice=>1, :remaining=>1, :cum=>1} 1 {:juice=>1, :remaining=>1, :cum=>2} - 1 {:juice=>1, :remaining=>1, :cum=>2} Exiting 1 {:juice=>1, :remaining=>1, :cum=>2} - 2 {:juice=>2, :remaining=>1, :cum=>4} 2 {:juice=>2, :remaining=>1, :cum=>4} - 0 {:juice=>1, :remaining=>1, :cum=>1} 2 {:juice=>2, :remaining=>1, :cum=>4} - 1 {:juice=>1, :remaining=>1, :cum=>2} Exiting 2 {:juice=>2, :remaining=>1, :cum=>4} - 2 {:juice=>2, :remaining=>1, :cum=>4} 3 {:juice=>10, :remaining=>0, :cum=>14} - 0 {:juice=>1, :remaining=>1, :cum=>1} 3 {:juice=>10, :remaining=>0, :cum=>14} - 1 {:juice=>1, :remaining=>1, :cum=>2} 3 {:juice=>10, :remaining=>0, :cum=>14} - 2 {:juice=>2, :remaining=>1, :cum=>4} Exiting 3 {:juice=>10, :remaining=>0, :cum=>14} - 3 {:juice=>10, :remaining=>0, :cum=>14}
[{:juice=>1, :remaining=>2, :cum=>1}, {:juice=>2, :remaining=>4, :cum=>3}, {:juice=>3, :remaining=>1, :cum=>6}, {:juice=>4, :remaining=>0, :cum=>10}] 0 {:juice=>1, :remaining=>2, :cum=>1} - 0 {:juice=>1, :remaining=>2, :cum=>1} 0 {:juice=>1, :remaining=>2, :cum=>1} - 1 {:juice=>2, :remaining=>4, :cum=>3} Exiting 0 {:juice=>1, :remaining=>2, :cum=>1} - 2 {:juice=>3, :remaining=>1, :cum=>6} 1 {:juice=>2, :remaining=>4, :cum=>3} - 0 {:juice=>1, :remaining=>2, :cum=>1} 1 {:juice=>2, :remaining=>4, :cum=>3} - 1 {:juice=>2, :remaining=>4, :cum=>3} 1 {:juice=>2, :remaining=>4, :cum=>3} - 2 {:juice=>3, :remaining=>1, :cum=>6} Exiting 1 {:juice=>2, :remaining=>4, :cum=>3} - 3 {:juice=>4, :remaining=>0, :cum=>10} 2 {:juice=>3, :remaining=>1, :cum=>6} - 0 {:juice=>1, :remaining=>2, :cum=>1} 2 {:juice=>3, :remaining=>1, :cum=>6} - 1 {:juice=>2, :remaining=>4, :cum=>3} Exiting 2 {:juice=>3, :remaining=>1, :cum=>6} - 2 {:juice=>3, :remaining=>1, :cum=>6} 3 {:juice=>4, :remaining=>0, :cum=>10} - 0 {:juice=>1, :remaining=>2, :cum=>1} 3 {:juice=>4, :remaining=>0, :cum=>10} - 1 {:juice=>2, :remaining=>4, :cum=>3} Exiting 3 {:juice=>4, :remaining=>0, :cum=>10} - 2 {:juice=>3, :remaining=>1, :cum=>6}
[{:juice=>2, :remaining=>1, :cum=>2}, {:juice=>3, :remaining=>1, :cum=>5}] 0 {:juice=>2, :remaining=>1, :cum=>2} - 0 {:juice=>2, :remaining=>1, :cum=>2} Exiting 0 {:juice=>2, :remaining=>1, :cum=>2} - 1 {:juice=>3, :remaining=>1, :cum=>5} 1 {:juice=>3, :remaining=>1, :cum=>5} - 0 {:juice=>2, :remaining=>1, :cum=>2} Exiting 1 {:juice=>3, :remaining=>1, :cum=>5} - 1 {:juice=>3, :remaining=>1, :cum=>5}
[{:juice=>1, :remaining=>5, :cum=>1}, {:juice=>1, :remaining=>4, :cum=>2}, {:juice=>5, :remaining=>3, :cum=>7}] 0 {:juice=>1, :remaining=>5, :cum=>1} - 0 {:juice=>1, :remaining=>5, :cum=>1} 0 {:juice=>1, :remaining=>5, :cum=>1} - 1 {:juice=>1, :remaining=>4, :cum=>2} Exiting 0 {:juice=>1, :remaining=>5, :cum=>1} - 2 {:juice=>5, :remaining=>3, :cum=>7} 1 {:juice=>1, :remaining=>4, :cum=>2} - 0 {:juice=>1, :remaining=>5, :cum=>1} 1 {:juice=>1, :remaining=>4, :cum=>2} - 1 {:juice=>1, :remaining=>4, :cum=>2} Exiting 1 {:juice=>1, :remaining=>4, :cum=>2} - 2 {:juice=>5, :remaining=>3, :cum=>7} 2 {:juice=>5, :remaining=>3, :cum=>7} - 0 {:juice=>1, :remaining=>5, :cum=>1} 2 {:juice=>5, :remaining=>3, :cum=>7} - 1 {:juice=>1, :remaining=>4, :cum=>2} 2 {:juice=>5, :remaining=>3, :cum=>7} - 2 {:juice=>5, :remaining=>3, :cum=>7}
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
#puts "here"
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
#puts "#{i} #{j}"
#puts "here"
if j < i and _t[:cum] <= remaining
puts "j<#{i} #{t} - #{j} #{_t}"
max_mix = [j+2,max_mix].max
next
end
if _t[:cum] - t[:juice] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
puts "Exiting #{i} #{t} - #{j} #{_t}"
break
end
end
max_mix
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
#puts "here"
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
#puts "#{i} #{j}"
#puts "here"
if j < i and _t[:cum] <= remaining
puts "j<i #{i} #{t} - #{j} #{_t}"
max_mix = [j+2,max_mix].max
next
end
if _t[:cum] - t[:juice] <= remaining
puts "#{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
puts "Exiting #{i} #{t} - #{j} #{_t}"
break
end
end
max_mix
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
#puts "here"
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
#puts "#{i} #{j}"
#puts "here"
if j < i and _t[:cum] <= remaining
puts "j<i #{i} #{t} - #{j} #{_t}"
max_mix = [j+2,max_mix].max
next
end
if _t[:cum] - t[:juice] <= remaining
puts "j>=i #{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
puts "Exiting #{i} #{t} - #{j} #{_t}"
break
end
end
max_mix
end
[{:juice=>1, :remaining=>1, :cum=>1}, {:juice=>1, :remaining=>1, :cum=>2}, {:juice=>2, :remaining=>1, :cum=>4}, {:juice=>10, :remaining=>0, :cum=>14}] j>=i 0 {:juice=>1, :remaining=>1, :cum=>1} - 0 {:juice=>1, :remaining=>1, :cum=>1} j>=i 0 {:juice=>1, :remaining=>1, :cum=>1} - 1 {:juice=>1, :remaining=>1, :cum=>2} Exiting 0 {:juice=>1, :remaining=>1, :cum=>1} - 2 {:juice=>2, :remaining=>1, :cum=>4} j<i 1 {:juice=>1, :remaining=>1, :cum=>2} - 0 {:juice=>1, :remaining=>1, :cum=>1} j>=i 1 {:juice=>1, :remaining=>1, :cum=>2} - 1 {:juice=>1, :remaining=>1, :cum=>2} Exiting 1 {:juice=>1, :remaining=>1, :cum=>2} - 2 {:juice=>2, :remaining=>1, :cum=>4} j<i 2 {:juice=>2, :remaining=>1, :cum=>4} - 0 {:juice=>1, :remaining=>1, :cum=>1} j>=i 2 {:juice=>2, :remaining=>1, :cum=>4} - 1 {:juice=>1, :remaining=>1, :cum=>2} Exiting 2 {:juice=>2, :remaining=>1, :cum=>4} - 2 {:juice=>2, :remaining=>1, :cum=>4} j>=i 3 {:juice=>10, :remaining=>0, :cum=>14} - 0 {:juice=>1, :remaining=>1, :cum=>1} j>=i 3 {:juice=>10, :remaining=>0, :cum=>14} - 1 {:juice=>1, :remaining=>1, :cum=>2} j>=i 3 {:juice=>10, :remaining=>0, :cum=>14} - 2 {:juice=>2, :remaining=>1, :cum=>4} Exiting 3 {:juice=>10, :remaining=>0, :cum=>14} - 3 {:juice=>10, :remaining=>0, :cum=>14}
[{:juice=>1, :remaining=>2, :cum=>1}, {:juice=>2, :remaining=>4, :cum=>3}, {:juice=>3, :remaining=>1, :cum=>6}, {:juice=>4, :remaining=>0, :cum=>10}] j>=i 0 {:juice=>1, :remaining=>2, :cum=>1} - 0 {:juice=>1, :remaining=>2, :cum=>1} j>=i 0 {:juice=>1, :remaining=>2, :cum=>1} - 1 {:juice=>2, :remaining=>4, :cum=>3} Exiting 0 {:juice=>1, :remaining=>2, :cum=>1} - 2 {:juice=>3, :remaining=>1, :cum=>6} j<i 1 {:juice=>2, :remaining=>4, :cum=>3} - 0 {:juice=>1, :remaining=>2, :cum=>1} j>=i 1 {:juice=>2, :remaining=>4, :cum=>3} - 1 {:juice=>2, :remaining=>4, :cum=>3} j>=i 1 {:juice=>2, :remaining=>4, :cum=>3} - 2 {:juice=>3, :remaining=>1, :cum=>6} Exiting 1 {:juice=>2, :remaining=>4, :cum=>3} - 3 {:juice=>4, :remaining=>0, :cum=>10} j<i 2 {:juice=>3, :remaining=>1, :cum=>6} - 0 {:juice=>1, :remaining=>2, :cum=>1} j>=i 2 {:juice=>3, :remaining=>1, :cum=>6} - 1 {:juice=>2, :remaining=>4, :cum=>3} Exiting 2 {:juice=>3, :remaining=>1, :cum=>6} - 2 {:juice=>3, :remaining=>1, :cum=>6} j>=i 3 {:juice=>4, :remaining=>0, :cum=>10} - 0 {:juice=>1, :remaining=>2, :cum=>1} j>=i 3 {:juice=>4, :remaining=>0, :cum=>10} - 1 {:juice=>2, :remaining=>4, :cum=>3} Exiting 3 {:juice=>4, :remaining=>0, :cum=>10} - 2 {:juice=>3, :remaining=>1, :cum=>6}
[{:juice=>2, :remaining=>1, :cum=>2}, {:juice=>3, :remaining=>1, :cum=>5}] j>=i 0 {:juice=>2, :remaining=>1, :cum=>2} - 0 {:juice=>2, :remaining=>1, :cum=>2} Exiting 0 {:juice=>2, :remaining=>1, :cum=>2} - 1 {:juice=>3, :remaining=>1, :cum=>5} j>=i 1 {:juice=>3, :remaining=>1, :cum=>5} - 0 {:juice=>2, :remaining=>1, :cum=>2} Exiting 1 {:juice=>3, :remaining=>1, :cum=>5} - 1 {:juice=>3, :remaining=>1, :cum=>5}
[{:juice=>1, :remaining=>5, :cum=>1}, {:juice=>1, :remaining=>4, :cum=>2}, {:juice=>5, :remaining=>3, :cum=>7}] j>=i 0 {:juice=>1, :remaining=>5, :cum=>1} - 0 {:juice=>1, :remaining=>5, :cum=>1} j>=i 0 {:juice=>1, :remaining=>5, :cum=>1} - 1 {:juice=>1, :remaining=>4, :cum=>2} Exiting 0 {:juice=>1, :remaining=>5, :cum=>1} - 2 {:juice=>5, :remaining=>3, :cum=>7} j<i 1 {:juice=>1, :remaining=>4, :cum=>2} - 0 {:juice=>1, :remaining=>5, :cum=>1} j>=i 1 {:juice=>1, :remaining=>4, :cum=>2} - 1 {:juice=>1, :remaining=>4, :cum=>2} Exiting 1 {:juice=>1, :remaining=>4, :cum=>2} - 2 {:juice=>5, :remaining=>3, :cum=>7} j<i 2 {:juice=>5, :remaining=>3, :cum=>7} - 0 {:juice=>1, :remaining=>5, :cum=>1} j<i 2 {:juice=>5, :remaining=>3, :cum=>7} - 1 {:juice=>1, :remaining=>4, :cum=>2} j>=i 2 {:juice=>5, :remaining=>3, :cum=>7} - 2 {:juice=>5, :remaining=>3, :cum=>7}
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
#puts "here"
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
#puts "#{i} #{j}"
#puts "here"
if j < i and _t[:cum] <= remaining
puts "j<i #{i} #{t} - #{j} #{_t}"
max_mix = [j+2,max_mix].max
next
end
if j_t[:cum] - t[:juice] <= remaining
puts "j>=i #{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
puts "Exiting #{i} #{t} - #{j} #{_t}"
break
end
end
max_mix
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
#puts "here"
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
#puts "#{i} #{j}"
#puts "here"
if j < i and _t[:cum] <= remaining
puts "j<i #{i} #{t} - #{j} #{_t}"
max_mix = [j+2,max_mix].max
next
end
if j >=i and _t[:cum] - t[:juice] <= remaining
puts "j>=i #{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
puts "Exiting #{i} #{t} - #{j} #{_t}"
break
end
end
max_mix
end
[{:juice=>1, :remaining=>1, :cum=>1}, {:juice=>1, :remaining=>1, :cum=>2}, {:juice=>2, :remaining=>1, :cum=>4}, {:juice=>10, :remaining=>0, :cum=>14}] j>=i 0 {:juice=>1, :remaining=>1, :cum=>1} - 0 {:juice=>1, :remaining=>1, :cum=>1} j>=i 0 {:juice=>1, :remaining=>1, :cum=>1} - 1 {:juice=>1, :remaining=>1, :cum=>2} Exiting 0 {:juice=>1, :remaining=>1, :cum=>1} - 2 {:juice=>2, :remaining=>1, :cum=>4} j<i 1 {:juice=>1, :remaining=>1, :cum=>2} - 0 {:juice=>1, :remaining=>1, :cum=>1} j>=i 1 {:juice=>1, :remaining=>1, :cum=>2} - 1 {:juice=>1, :remaining=>1, :cum=>2} Exiting 1 {:juice=>1, :remaining=>1, :cum=>2} - 2 {:juice=>2, :remaining=>1, :cum=>4} j<i 2 {:juice=>2, :remaining=>1, :cum=>4} - 0 {:juice=>1, :remaining=>1, :cum=>1} Exiting 2 {:juice=>2, :remaining=>1, :cum=>4} - 1 {:juice=>1, :remaining=>1, :cum=>2} Exiting 3 {:juice=>10, :remaining=>0, :cum=>14} - 0 {:juice=>1, :remaining=>1, :cum=>1}
[{:juice=>1, :remaining=>2, :cum=>1}, {:juice=>2, :remaining=>4, :cum=>3}, {:juice=>3, :remaining=>1, :cum=>6}, {:juice=>4, :remaining=>0, :cum=>10}] j>=i 0 {:juice=>1, :remaining=>2, :cum=>1} - 0 {:juice=>1, :remaining=>2, :cum=>1} j>=i 0 {:juice=>1, :remaining=>2, :cum=>1} - 1 {:juice=>2, :remaining=>4, :cum=>3} Exiting 0 {:juice=>1, :remaining=>2, :cum=>1} - 2 {:juice=>3, :remaining=>1, :cum=>6} j<i 1 {:juice=>2, :remaining=>4, :cum=>3} - 0 {:juice=>1, :remaining=>2, :cum=>1} j>=i 1 {:juice=>2, :remaining=>4, :cum=>3} - 1 {:juice=>2, :remaining=>4, :cum=>3} j>=i 1 {:juice=>2, :remaining=>4, :cum=>3} - 2 {:juice=>3, :remaining=>1, :cum=>6} Exiting 1 {:juice=>2, :remaining=>4, :cum=>3} - 3 {:juice=>4, :remaining=>0, :cum=>10} j<i 2 {:juice=>3, :remaining=>1, :cum=>6} - 0 {:juice=>1, :remaining=>2, :cum=>1} Exiting 2 {:juice=>3, :remaining=>1, :cum=>6} - 1 {:juice=>2, :remaining=>4, :cum=>3} Exiting 3 {:juice=>4, :remaining=>0, :cum=>10} - 0 {:juice=>1, :remaining=>2, :cum=>1}
[{:juice=>2, :remaining=>1, :cum=>2}, {:juice=>3, :remaining=>1, :cum=>5}] j>=i 0 {:juice=>2, :remaining=>1, :cum=>2} - 0 {:juice=>2, :remaining=>1, :cum=>2} Exiting 0 {:juice=>2, :remaining=>1, :cum=>2} - 1 {:juice=>3, :remaining=>1, :cum=>5} Exiting 1 {:juice=>3, :remaining=>1, :cum=>5} - 0 {:juice=>2, :remaining=>1, :cum=>2}
[{:juice=>1, :remaining=>5, :cum=>1}, {:juice=>1, :remaining=>4, :cum=>2}, {:juice=>5, :remaining=>3, :cum=>7}] j>=i 0 {:juice=>1, :remaining=>5, :cum=>1} - 0 {:juice=>1, :remaining=>5, :cum=>1} j>=i 0 {:juice=>1, :remaining=>5, :cum=>1} - 1 {:juice=>1, :remaining=>4, :cum=>2} Exiting 0 {:juice=>1, :remaining=>5, :cum=>1} - 2 {:juice=>5, :remaining=>3, :cum=>7} j<i 1 {:juice=>1, :remaining=>4, :cum=>2} - 0 {:juice=>1, :remaining=>5, :cum=>1} j>=i 1 {:juice=>1, :remaining=>4, :cum=>2} - 1 {:juice=>1, :remaining=>4, :cum=>2} Exiting 1 {:juice=>1, :remaining=>4, :cum=>2} - 2 {:juice=>5, :remaining=>3, :cum=>7} j<i 2 {:juice=>5, :remaining=>3, :cum=>7} - 0 {:juice=>1, :remaining=>5, :cum=>1} j<i 2 {:juice=>5, :remaining=>3, :cum=>7} - 1 {:juice=>1, :remaining=>4, :cum=>2} j>=i 2 {:juice=>5, :remaining=>3, :cum=>7} - 2 {:juice=>5, :remaining=>3, :cum=>7}
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
#puts "here"
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
#puts "#{i} #{j}"
#puts "here"
if j < i and _t[:cum] <= remaining
puts "j<i #{i} #{t} - #{j} #{_t}"
max_mix = [j+2,max_mix].max
next
end
if j >=i and _t[:cum] - t[:juice] <= remaining
#puts "j>=i #{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
puts "Exiting #{i} #{t} - #{j} #{_t}"
break
end
end
max_mix
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
#puts "here"
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
#puts "#{i} #{j}"
#puts "here"
if j < i and _t[:cum] <= remaining
#puts "j<i #{i} #{t} - #{j} #{_t}"
max_mix = [j+2,max_mix].max
next
end
if j >=i and _t[:cum] - t[:juice] <= remaining
#puts "j>=i #{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
#puts "Exiting #{i} #{t} - #{j} #{_t}"
break
end
end
max_mix
end
[{:juice=>1, :remaining=>1, :cum=>1}, {:juice=>1, :remaining=>1, :cum=>2}, {:juice=>2, :remaining=>1, :cum=>4}, {:juice=>10, :remaining=>0, :cum=>14}]
[{:juice=>1, :remaining=>2, :cum=>1}, {:juice=>2, :remaining=>4, :cum=>3}, {:juice=>3, :remaining=>1, :cum=>6}, {:juice=>4, :remaining=>0, :cum=>10}]
[{:juice=>2, :remaining=>1, :cum=>2}, {:juice=>3, :remaining=>1, :cum=>5}]
[{:juice=>1, :remaining=>5, :cum=>1}, {:juice=>1, :remaining=>4, :cum=>2}, {:juice=>5, :remaining=>3, :cum=>7}]
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
#puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
#puts "here"
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
#puts "#{i} #{j}"
#puts "here"
if j < i and _t[:cum] <= remaining
#puts "j<i #{i} #{t} - #{j} #{_t}"
max_mix = [j+2,max_mix].max
next
end
if j >=i and _t[:cum] - t[:juice] <= remaining
#puts "j>=i #{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
#puts "Exiting #{i} #{t} - #{j} #{_t}"
break
end
end
max_mix
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
#puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
#puts "here"
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
#puts "#{i} #{j}"
#puts "here"
if j < i and _t[:cum] <= remaining
#puts "j<i #{i} #{t} - #{j} #{_t}"
max_mix = [j+2,max_mix].max
next
end
if j >=i and _t[:cum] - t[:juice] <= remaining
#puts "j>=i #{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
#puts "Exiting #{i} #{t} - #{j} #{_t}"
break
end
end
max_mix
end
# you can write to stdout for debugging purposes, e.g.
# puts "this is a debug message"
def solution(juice, capacity)
# write your code in Ruby 2.2
tuple = []
juice.each_with_index do |_juice,i|
tuple << {juice: _juice, remaining: capacity[i] - _juice}
end
tuple.sort_by! {|t| t[:juice] }
sum = 0
tuple.each do |t|
sum += t[:juice]
t[:cum] = sum
end
#puts tuple.inspect
max_mix = 1
tuple.each_with_index do |t,i|
#puts "here"
remaining = t[:remaining]
tuple.each_with_index do |_t,j|
#puts "#{i} #{j}"
#puts "here"
if j < i and _t[:cum] <= remaining
#puts "j<i #{i} #{t} - #{j} #{_t}"
max_mix = [j+2,max_mix].max
next
end
if j >=i and _t[:cum] - t[:juice] <= remaining
#puts "j>=i #{i} #{t} - #{j} #{_t}"
max_mix = [j+1,max_mix].max
next
end
#puts "Exiting #{i} #{t} - #{j} #{_t}"
break
end
end
max_mix
end
The following issues have been detected: timeout errors.
Tests in which the glass with the biggest capacity is not the one that should be picked as the base.
Tests in which the glass with the largest empty space is not the picked as the base.
All kind of tests, N <= 100,000. Points x 2.
Killed. Hard limit reached: 7.000 sec.
Big tests with extreme values. Points x 2.
Killed. Hard limit reached: 7.000 sec.
Tests in which glasses have big capacity. Points x 2.
Killed. Hard limit reached: 7.000 sec.