import itertools from codejam import CodeJam cj = CodeJam(debug=False) for case in cj.cases: elements = cj.get_int() v1 = map(int, cj.get_lines(1)[0].split(' ')) v2 = map(int, cj.get_lines(1)[0].split(' ')) total = 0 if max(v1) > max(v2): v1.sort(reverse=True) v2.sort() else: v2.sort(reverse=True) v1.sort() for i in xrange(elements): total += v1[i] * v2[i] print total cj.write_case(total)
import itertools import decimal import math from codejam import CodeJam cj = CodeJam(debug=False) three = decimal.Decimal(3) five = decimal.Decimal(5).sqrt() for case in cj.cases: n = cj.get_int() total = (three + five)**n t = total.to_eng_string() entera = t.split('.', 1)[0] print entera, t cj.write_case(entera[-3:].zfill(3))
break else: for word in words[i:]: actual = words[i:].index(word) if actual >= candidate[0] and actual != 0: candidate = (actual, word) ret_word_dict.append(candidate) return ret_word_dict cj = CodeJam(debug=False) cases = cj.get_int() for case in xrange(cases): search_engines = cj.get_lines(cj.get_int()) words = cj.get_lines(cj.get_int()) switch = 0 if words: words_best = get_words_count(words, search_engines) actual = '' for i in xrange(len(words)): if i == 0 or actual == words[i]: actual = words_best[i][1] if i != 0: switch += 1 print switch cj.write_case(switch)