about summary refs log tree commit diff
path: root/codechef/maxrem.py
diff options
context:
space:
mode:
Diffstat (limited to 'codechef/maxrem.py')
-rwxr-xr-xcodechef/maxrem.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/codechef/maxrem.py b/codechef/maxrem.py
new file mode 100755
index 0000000..30087c7
--- /dev/null
+++ b/codechef/maxrem.py
@@ -0,0 +1,20 @@
+#!/usr/bin/env python3
+from bisect import bisect   # bisect takes no key argument. What a dick.
+
+input()
+a = [-int(i) for i in input().split()]
+a.sort()
+
+res = 0
+for i in a:
+    if i > res: break
+    for j in range(i, a[0] + i, i):
+        idx = bisect(a, j)
+        try:
+            tmp = a[idx] % i
+        except IndexError:
+            continue
+        if tmp < res: res = tmp
+        if res == i + 1: break
+
+print(-res)