From 6c3729317728a1a97c8ab06ac40a635f31845bc9 Mon Sep 17 00:00:00 2001 From: Titouan Rigoudy Date: Sat, 27 Sep 2014 01:50:04 -0400 Subject: [PATCH] Solved Cut the Sticks --- cut_the_sticks/cut_the_sticks.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 cut_the_sticks/cut_the_sticks.py diff --git a/cut_the_sticks/cut_the_sticks.py b/cut_the_sticks/cut_the_sticks.py new file mode 100644 index 0000000..398b613 --- /dev/null +++ b/cut_the_sticks/cut_the_sticks.py @@ -0,0 +1,25 @@ +#!/usr/bin/python3 + +# https://www.hackerrank.com/challenges/cut-the-sticks + +import sys + +def print_cuts(N, lengths): + max_length = 0 + sticks = [ 0 ] * 1000 + for length in lengths: + sticks[length] += 1 + max_length = max(max_length,length) + + for length in range(max_length + 1): + if sticks[length] > 0: + print(N) + N -= sticks[length] + +def main(): + N = int(sys.stdin.readline()) + lengths = [ int(x) for x in sys.stdin.readline().split() ] + print_cuts(N,lengths) + +if __name__ == '__main__': + main() \ No newline at end of file