Skip to content

Instantly share code, notes, and snippets.

@seniorihor
Created March 11, 2012 20:02
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save seniorihor/2017959 to your computer and use it in GitHub Desktop.
Save seniorihor/2017959 to your computer and use it in GitHub Desktop.
Рішення задачі "Приїзд генерала" з http://codeforces.ru/contest/144/problem/A
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-
# Aurhor: seniorihor (12.03.2012)
class General
def initialize(quantity, numbers)
@quantity = quantity
@numbers = numbers
@seconds = 0
end
def calculation_seconds
if @numbers.rindex(@numbers.min) > @numbers.index(@numbers.max)
@seconds = @numbers.index(@numbers.max) + @numbers.length - 1 - @numbers.rindex(@numbers.min)
else
@seconds = @numbers.index(@numbers.max) + @numbers.length - 2 - @numbers.rindex(@numbers.min)
end
end
end
quantity = gets.chomp.to_i
numbers = gets.chomp.split(" ").map! do |i|
i = i.to_i
end
g = General.new(quantity, numbers)
p g.calculation_seconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment