Skip to content

Instantly share code, notes, and snippets.

@erukiti
Created June 16, 2012 13:35
Show Gist options
  • Save erukiti/2941351 to your computer and use it in GitHub Desktop.
Save erukiti/2941351 to your computer and use it in GitHub Desktop.
ARC#004 B問題
#! /usr/bin/env ruby
# coding: utf-8
n = STDIN.gets.to_i
pt = []
max = 0
sum = 0
list = []
(0...n).each do |i|
a = STDIN.gets.strip.to_i
list[i] = a
max = a if max < a
sum += a
end
print "#{sum}\n"
if n == 1
print "#{sum}\n"
elsif n == 2
print "#{(list[0] - list[1]).abs}\n"
elsif sum - max > max
print "0\n"
else
max += max
(0...n).each do |i|
max -= list[i]
end
print "#{max}\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment