Skip to content

Instantly share code, notes, and snippets.

@kamath
Created January 28, 2017 20:51
Show Gist options
  • Select an option

  • Save kamath/00b18f104b17d430a1e32910e08da539 to your computer and use it in GitHub Desktop.

Select an option

Save kamath/00b18f104b17d430a1e32910e08da539 to your computer and use it in GitHub Desktop.
#!/bin/python
import sys
#Define Box class and methods
class box:
boxes = []
def __init__(self, arr):
self.boxes = arr
#Methods 1, 2, 3, and 4 as defined by HR
def one(self, l, r, c):
for a in range(l, r+1):
self.boxes[a] += c
def two(self, l, r, c):
for a in range(l, r+1):
self.boxes[a] /= c
def three(self, l, r):
print min(self.boxes[l:r+1])
def four(self, l, r):
print sum(self.boxes[l:r+1])
n,q = raw_input().strip().split(' ')
n,q = [int(n),int(q)]
b = box(map(int, raw_input().strip().split(' ')))
#Methods dictionary to make calling the methods easier
methods = {'1': b.one, '2': b.two, '3': b.three, '4': b.four}
for i in range(q):
a = raw_input().split(' ')
#Call the methods lmao
methods[a[0]](*map(int, a[1:]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment