-
-
Save paul-ihnatolia/2018506 to your computer and use it in GitHub Desktop.
Рішення задачі "Приїзд генерала" з http://codeforces.ru/contest/144/problem/A
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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