Skip to content

Instantly share code, notes, and snippets.

@paul-ihnatolia
Forked from seniorihor/general.rb
Created March 11, 2012 22:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paul-ihnatolia/2018506 to your computer and use it in GitHub Desktop.
Save paul-ihnatolia/2018506 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 and vertoldo (12.03.2012)
class General
def initialize(quantity, numbers)
@quantity = quantity
@numbers = numbers
@posMensh=0
@posBilsh=0
@sec=0
end
def calculation_seconds
@numbers.size().times do |j|
if(@numbers[@posBilsh]<@numbers[j])
@posBilsh=j
end
end
@posMensh=@quantity-1
i=@posMensh
while(i>=0)
if(@numbers[@posMensh]>@numbers[i])
@posMensh=i
end
i-=1
end
@sec+=@posBilsh
@sec+=(@quantity-1-@posMensh)
@sec-=1 if(@posBilsh>@posMensh)
return @sec
end
end
quantity = gets.chomp.to_i
numbers = gets.chomp.split(" ").map! {|el| el=el.to_i}
g = General.new(quantity, numbers)
print g.calculation_seconds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment