• API
• FAQ
• Tools
• Archive
SHARE
TWEET

# Untitled

a guest Mar 19th, 2019 46 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
1. from math import *
2. n = int(input())
3. a = list(map(int, input().split()))
4. ln = int(sqrt(n) + 1)
5. b = [0 for i in range(ln + 100)]
6. for i in range(n):
7.     b[i // ln] += a[i]
8. seq = []
9. for l in range(n):
10.     for r in range(n):
11.         if r < l:
12.             continue
13.         sm = 0
14.         i = l
15.         while i <= r:
16.             if i % ln == 0 and i + ln - 1 <= r:
17.                 sm += b[i // ln]
18.                 i += ln
19.             else:
20.                 sm += a[i]
21.                 i += 1
22.         seq.append((l, r, sm))
23.
24. d = dict()
25. for i in seq:
26.     d[i[2]] = []
27.
28. for i in seq:
29.     if d[i[2]] == []:
30.         d[i[2]].append((i[0] + 1, i[1] + 1))
31.         continue
32.     if i[0] + 1 > d[i[2]][-1][1]:
33.         d[i[2]].append((i[0] + 1, i[1] + 1))
34.
35. ans = []
36. for i in d.keys():
37.     if len(d[i]) > len(ans):
38.         ans = d[i]
39. print(len(ans))
40. for i in ans:
41.     print(i[0], i[1])
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy.
Not a member of Pastebin yet?