Created
February 8, 2015 02:17
-
-
Save zsrinivas/0a0d0f24f5dbd5cba915 to your computer and use it in GitHub Desktop.
code-marathon-div-2 round3 solutions
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 python | |
# -*- encoding: utf-8 -*- | |
# pylint: disable=C0111 | |
'''input | |
3 | |
3 8 | |
2 5 | |
11 3 | |
''' | |
def main(): | |
def gcd(a, b): | |
while b: | |
a, b = b, a % b | |
return a | |
for _ in xrange(int(raw_input())): | |
a, b = map(int, raw_input().split()) | |
print a // gcd(a, b) | |
main() |
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 python | |
# -*- encoding: utf-8 -*- | |
# pylint: disable=C0111 | |
# from sys import stdin | |
'''input | |
2 | |
5 | |
2 8 3 6 7 | |
1 1 1 1 1 | |
5 | |
2 8 3 6 7 | |
1 4 3 2 1 | |
''' | |
def main(): | |
for _ in xrange(int(raw_input())): | |
n = int(raw_input()) | |
coins = map(int, raw_input().split()) | |
number = map(int, raw_input().split()) | |
mc = [float('-inf')] * n | |
mc[-1] = coins[-1] | |
for x in xrange(n - 2, -1, -1): | |
mca = float('-inf') | |
for par in (x + number[x], x + number[x] + 1, x + number[x] + 2): | |
if par < n: | |
mca = max(mca, mc[par]) | |
mc[x] = mca + coins[x] | |
if mc[0] == float('-inf'): | |
print -1 | |
else: | |
print mc[0] | |
main() |
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 python | |
# -*- encoding: utf-8 -*- | |
# pylint: disable=C0111 | |
'''input | |
5 | |
1 5 1 | |
1 6 2 | |
2 12 | |
1 1 1 | |
2 5 | |
''' | |
def main(): | |
army = {} | |
for t in xrange(int(raw_input())): | |
query = map(int, raw_input().split()) | |
if query[0] == 1: | |
army[query[1]] = (query[2], t) | |
else: | |
n = query[1] | |
recent = (0, -1) | |
while n != 0: | |
try: | |
if recent[1] < army[n][1]: | |
recent = army[n] | |
except KeyError: | |
pass | |
n //= 2 | |
print recent[0] | |
main() |
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 python | |
# -*- encoding: utf-8 -*- | |
# pylint: disable=C0111 | |
from sys import stdin | |
def main(): | |
n, c = map(int, raw_input().split()) | |
inp = map(int, stdin.read().split()) | |
xcor = inp[::2] | |
ycor = inp[1::2] | |
xcor.sort() | |
ycor.sort() | |
if n % 2: | |
x, y = xcor[n // 2], ycor[n // 2] | |
else: | |
x, y = ( | |
(xcor[n // 2] + xcor[n // 2 - 1]) // 2, | |
(ycor[n // 2] + ycor[n // 2 - 1]) // 2) | |
s = 0 | |
for i in xrange(n): | |
s += abs(xcor[i] - x) | |
s += abs(ycor[i] - y) | |
print s*c | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment