Created
April 12, 2017 03:40
-
-
Save whatalnk/5a316e3dbce0152f4de19051192e154a to your computer and use it in GitHub Desktop.
AtCoder ABC #009
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
n = gets.chomp.to_i | |
if n % 2 == 0 then | |
puts n / 2 | |
else | |
puts n / 2 + 1 | |
end |
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
n = gets.chomp.to_i | |
prices = [] | |
n.times do | |
prices << gets.chomp.to_i | |
end | |
puts prices.sort.uniq[-2] |
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
n, k = gets.chomp.split(" ").map(&:to_i) | |
s = gets.chomp.split("") | |
def diff(s, s2) | |
return 0 if s.empty? && s2.empty? | |
h = Hash.new(0) | |
s.each{|c| h[c] += 1} | |
s2.each{|c| h[c] -= 1} | |
return h.values.map{|v| v.abs}.inject(:+) / 2 | |
end | |
rem = s.dup.sort | |
ret = [] | |
d = 0 | |
n.times do |i| | |
rem2 = [] | |
rem.each_with_index do |c, j| | |
ret << c | |
dd = 0 | |
if ret[i] != s[i] then | |
dd = 1 | |
end | |
if d + dd + diff(s[(i+1)..-1], rem2 + rem[(j+1)..-1]) <= k then | |
rem.slice!(j) | |
d += dd | |
break | |
else | |
rem2 << ret.pop | |
end | |
end | |
end | |
puts ret.join("") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment