submission_id
string
problem_id
string
status
string
code
string
input
string
output
string
problem_description
string
s581737886
p00022
Time Limit Exceeded
while True: n = int(input()) if n == 0: break dataset = [int(input()) for _ in range(n)] r = [] for i in range(n): for j in range(i, n + 1): r.append(sum(dataset[i:j])) print(sorted(r)[-1])
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s086117296
p00022
Time Limit Exceeded
while True: n = int(input()) m = 0 if n == 0: break dataset = [int(input()) for _ in range(n)] for i in range(n): for j in range(i, n + 1): s = sum(dataset[i:j]) if m < s: m = s print(m)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s887515301
p00022
Time Limit Exceeded
while True: n = int(input()) m = -1000000 if n == 0: break dataset = [int(input()) for _ in range(n)] for i in range(n): for j in range(i, n + 1): if dataset[i:j] != []: s = sum(dataset[i:j]) if m < s: m = s print(m)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s159638329
p00022
Time Limit Exceeded
while True: n = int(input()) m = -1000000 if not n : break dataset = [int(input()) for _ in range(n)] for i in range(n): for j in range(i, n + 1): if dataset[i:j] != []: s = sum(dataset[i:j]) if m < s: m = s print(m)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s481164854
p00022
Time Limit Exceeded
while 1: n=input() if n==0:break a=[int(raw_input()) for _ in xrange(n)] max_a=-1000000 for i in xrange(n): for j in xrange(i+1,n+1): if max_a<sum(a[i:j]): max_a=sum(a[i:j]) print(max_a)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s975981646
p00022
Time Limit Exceeded
while True: n = int(input()) if n == 0: break a = [] for _ in range(n): a.append(int(input())) print(max(max(sum(a[j:j + i + 1]) for j in range(n - i)) for i in range(n)))
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s922469131
p00022
Time Limit Exceeded
while True: n = int(input()) if n == 0: break a = [int(input()) for _ in range(n)] b = [] while a != []: for i in range(len(a)): if i == len(a) - 1 or a[i] * a[i + 1] < 0: b.append(sum(a[:i + 1])) a[:i + 1] = [] break print(max(max(sum(b[j:j + i + 1]) for j in range(len(b) - i)) for i in range(len(b))))
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s906814177
p00022
Time Limit Exceeded
while True: n = int(input()) if n==0: break sum_li = [int(input()) for i in range(n)] for i in range(2,n+1): for j in range(n-i+1): sum_li.append(sum(sum_li[j:j+i])) print(sorted(sum_li)[-1])
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s559541493
p00022
Time Limit Exceeded
while True: n = int(input()) if n == 0: break else: Sum = [] for i in range(n): Sum.append(int(input())) for i in range(2,n + 1): for j in range(n - i + 1): Wa = 0 for k in range(j,j + i): Wa += Sum[k] Sum.append(Wa) print(max(Sum))
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s549093805
p00022
Time Limit Exceeded
def solve(v): w = [] for i in range(len(v)): for j in range(len(v[i:])): w.append(sum(v[i:(j+1)])) return(max(w)) if __name__ == "__main__": while True: n = int(input()) if n == 0: break v = [] for i in range(n): v.append(int(input())) print(solve(v))
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s225546341
p00022
Time Limit Exceeded
def solve0(v): w = [] l = len(v) ans = max([sum(v[i:j+1]) for i in range(l) for j in range(i,l)]) return(ans) def sign(x): if x >= 0: s=+1 else: s=-1 return(s) def solve(v): w = [] sig=sign(v[0]) x = v[0] for i in range(1,len(v)): if v[i]==0: continue elif v[i] * sig > 0: x += v[i] else: w.append(x) sig=sign(v[i]) x=v[i] w.append(x) return(solve0(w)) if __name__ == "__main__": while True: n = int(input()) if n == 0: break v = [] for i in range(n): v.append(int(input())) print(solve(v))
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s965756400
p00022
Time Limit Exceeded
while True: n = int(input()) if n==0 : break a = [] for i in range(n): a.append(int(input())) maxi = 0 for i in range(1,1+n): for j in range(n-i+1): if maxi < sum(a[j:j+i]): maxi = sum(a[j:j+i]) print(maxi)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s769105939
p00022
Time Limit Exceeded
# -*- coding: utf-8 -*- import sys import os while True: s = input().strip() if s == '0': break N = int(s) A = [] for i in range(N): v = int(input()) A.append(v) max_value = 0 for start_i in range(N): for end_i in range(start_i + 1, N): sum_value = sum(A[start_i:end_i+1]) if sum_value > max_value: max_value = sum_value print(max_value)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s838288104
p00022
Time Limit Exceeded
def MSS(li): s = sum(li) l = len(li) for i in range(l): for j in range(l-i): if j == 0: continue e = l - j tmp = sum(li[i:e]) if s < tmp: s = tmp return s if __name__ == "__main__": assert MSS([-5, -1, 6, 4, 9, -6, -7]) == 19, "sample1" assert MSS([1, 2, 3, 2, -2, -1, 1, 2, 3, 2, 1, -2, 1]) == 14, "sample2" while True: n = int(input()) if n == 0: break li = [] for _ in range(n): li.append(int(input())) print(MSS(li))
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s839696599
p00022
Time Limit Exceeded
def MSS(li): s = sum(li) l = len(li) for i in range(l): for j in range(l-i): if j == 0: continue e = l - j tmp = sum(li[i:e]) if s < tmp: s = tmp return s if __name__ == "__main__": assert MSS([-5, -1, 6, 4, 9, -6, -7]) == 19, "sample1" assert MSS([1, 2, 3, 2, -2, -1, 1, 2, 3, 2, 1, -2, 1]) == 14, "sample2" answer = [] while True: n = int(input()) if n == 0: break li = [] for _ in range(n): li.append(int(input())) answer.append(MSS(li)) print(*answer, sep="\n")
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s454230148
p00022
Time Limit Exceeded
while True: N=int(input()) if N==0: break else: a=[] max=0 for i in range(N): a.append(int(input())) for i in range(N): for j in range(N+1): if sum(a[i:j])>=max: max=sum(a[i:j]) print(max)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s983835687
p00022
Time Limit Exceeded
while 1: n = input() if n == 0: break a = [] for i in range(n): k = input() a.append(k) print max([sum(a[i:(j+1)]) for i in range(n) for j in range(i,n)])
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s830305738
p00022
Time Limit Exceeded
import sys n = int(sys.stdin.readline()) while n: l = list() for _ in range(n): l.append(int(input())) maxs = 0 for i in range(n): for j in range(i,n): s = 0 for k in range(i,j+1): s += l[k] maxs = max(maxs,s) n = int(sys.stdin.readline()) print(maxs)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s118285237
p00022
Time Limit Exceeded
while True: n = int(input()) if n == 0: break sum_max = 0 a = [] for i in range(n): a.append(int(input())) for j in range(i + 1): sum_tmp = sum(a[j:i + 1]) if sum_tmp > sum_max: sum_max = sum_tmp print(sum_max)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s168813827
p00022
Time Limit Exceeded
def wa(a,x,y): S = 0 for i in range(x,y+1): S = S + a[i] return S n = int(input()) while n != 0: a = [] for i in range(n): a.append(int(input())) ans = a[0] for i in range(n): for j in range(i+1,n): ans = max(wa(a,i,j),ans) print(ans) n = int(input())
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s219478661
p00022
Time Limit Exceeded
import math def sign(x): if x >= 0: return True else: return False def wa(a,x,y): S = 0 for i in range(x,y+1): S = S + a[i] return S n = int(input()) while n != 0: a = [] for i in range(n): a.append(int(input())) b = [] b.append(a[0]) for i in range(1,len(a)): if sign(b[len(b)-1]) == sign(a[i]): b[len(b)-1] = b[len(b)-1] + a[i] else: b.append(a[i]) ans = b[0] for i in range(len(b)): for j in range(i,len(b)): ans = max(wa(b,i,j),ans) print(ans) n = int(input())
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s590962702
p00022
Time Limit Exceeded
while 1: n=int(input()) if n: a=[int(input())for _ in[0]*n] print(max(sum(a[i:j+1])for i in range(n)for j in range(i,n)))
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s325454669
p00022
Time Limit Exceeded
while 1: n=int(input()) if n: a=[int(input())for _ in[0]*n] print(max([sum(a[i:j+1])for i in range(n)for j in range(i,n)]))
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s905886586
p00022
Time Limit Exceeded
while 1: n=int(input()) if n==0:break a=[int(input())for _ in[0]*n] print(max(sum(a[i:j+1])for i in range(n)for j in range(i,n)))
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s419782647
p00022
Time Limit Exceeded
m=lambda x:max(map(max,[[sum(x[j:j+i+1]) for j in range(len(x)-i)] for i in range(len(x))])) while True: n=int(input()) if n==0:break print(m([int(input()) for i in range(n)]))
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s495709317
p00022
Time Limit Exceeded
while 1: n=int(input()) if not n:break l=[int(input()) for _ in range(n)] print(max(sum(l[j:i]) for i in range(len(l)+1) for j in range(i)))
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s121624282
p00022
Time Limit Exceeded
while 1: n=int(input()) if not n:break l=tuple([int(input()) for _ in range(n)]) print(max(sum(l[j:i]) for i in range(len(l)+1) for j in range(i)))
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s699143782
p00022
Time Limit Exceeded
while 1: m=0 l=[] n=int(input()) if not n: break for i in range(n): j=int(input()) if i==0: m+=j elif s*j<0: l.extend([m]) m=j else: m+=j s=j l.extend([m]) b=len(l) print(max([sum(l[i:j]) for j in range(1,b+1) for i in range(j)]))
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s725030760
p00022
Time Limit Exceeded
#!/usr/bin/env python #-*- coding:utf-8 -*- while True: n = input() if n == 0: break a = [ input() for i in xrange(n) ] m = -100000 for i in xrange(n): for j in xrange(n + 1): m = max(m, sum(a[i:j])) print m
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s869396622
p00022
Time Limit Exceeded
while 1: n=input() if(n==0):break a=[] for i in range(n): a.append(input()) ans=-100001 for i in range(n): for j in range(i+1,n+1): ans=max(ans,sum(a[i:j])) print ans
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s460021874
p00022
Time Limit Exceeded
while 1: n=input() if n == 0: break number = [0 for j in range(n)] sumpoyo = 0 for i in range(n): number[i] = input() for i in range(1, n+1): for k in range(n-i+1): a = number[k:k+i] #print i,k #print a temp = sum(a) if temp > sumpoyo: sumpoyo = temp print sumpoyo
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s982542821
p00022
Time Limit Exceeded
while True: a=int(input()) if a==0:break g=[] for i in range(a): g.append(int(input())) ans=0 for i in range(a): for j in range(a): hoge=sum(g[i:j+1]) if hoge > ans:ans = hoge print ans
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s979369244
p00022
Time Limit Exceeded
while True: n = int(raw_input()) if n == 0: break numbers = [] for i in range(n): numbers.append(int(raw_input())) sigmas = [] for i in range(1,n+1): for j in range(n+1-i): sigmas.append(reduce(lambda x,y:x+y,numbers[j:j+i+1])) print max(sigmas)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s583907972
p00022
Time Limit Exceeded
while True: n = int(raw_input()) if n == 0: break numbers = [] for i in range(n): numbers.append(int(raw_input())) sigmas = [] for i in range(1,n+1): for j in range(n+1-i): sigmas.append(reduce(lambda x,y:x+y,numbers[j:j+i+1])) print reduce(lambda x,y:x>y if x else y,sigmas)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s296774131
p00022
Time Limit Exceeded
while True: n = input(); if n == 0: break; l = [] for i in range(n): l.append(input()); print max([max([sum(l[i:j + 1]) for j in range(i, len(l))]) for i in range(len(l))])
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s684861043
p00022
Time Limit Exceeded
from __future__ import (absolute_import, division, print_function, unicode_literals) from sys import stdin while True: n = int(stdin.readline()) if not n: break m = 0 tup = tuple(int(stdin.readline()) for _ in xrange(n)) for i in xrange(len(tup)): for j in xrange(1 + i, len(tup) + 1): t = sum(tup[i:j]) if t > m: m = t print(m)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s252499451
p00022
Time Limit Exceeded
from __future__ import (absolute_import, division, print_function, unicode_literals) from sys import stdin while True: n = int(stdin.readline()) if not n: break tup = tuple(int(stdin.readline()) for _ in xrange(n)) L = [tup[0]] for i in tup[1:]: if 0 > i and 0 > L[-1]: L[-1] += i elif 0 <= i and 0 <= L[-1]: L[-1] += i else: L.append(i) m = 0 for i in xrange(len(L)): for j in xrange(1 + i, len(L) + 1): t = sum(L[i:j]) if t > m: m = t print(m)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s738429500
p00022
Time Limit Exceeded
from __future__ import (absolute_import, division, print_function, unicode_literals) from sys import stdin while True: n = int(stdin.readline()) if not n: break tup = tuple(int(stdin.readline()) for _ in xrange(n)) L = [tup[0]] for i in tup[1:]: if 0 > i and 0 > L[-1]: L[-1] += i elif 0 <= i and 0 <= L[-1]: L[-1] += i else: L.append(i) while True: length = len(L) if length > 1 and L[0] <= 0: L.pop(0) continue if length > 1 and L[-1] <= 0: L.pop() continue if length > 1 and L[0] + L[1] <= 0: L.pop(0) L.pop(0) continue if length > 1 and L[-1] + L[-2] <= 0: L.pop() L.pop() continue break print(L) m = 0 for i in xrange(len(L)): for j in xrange(1 + i, len(L) + 1): t = sum(L[i:j]) if t > m: m = t print(m)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s772910646
p00022
Time Limit Exceeded
import sys def max_sum_seq(lis): # r = [] m = 0 l = len(lis) for n in range(1, l+1): for s in every_slice(lis, n): sm = sum(s) if sm > m: m = sm return m # r = r + every_slice(lis, n) # return max(map((lambda r1: reduce((lambda x, y: x + y), r1, 0)), r)) def every_slice(lis, n): # r = [] l = len(lis) for i in range(l-n+1): yield lis[i:i+n] # return r #input_file = open(sys.argv[1], "r") while True: n = int(sys.stdin.readline()) if n == 0: break lis = [] for i in range(n): lis.append(int(sys.stdin.readline())) print max_sum_seq(lis)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s241361580
p00022
Time Limit Exceeded
import sys def max_sum_seq(lis): m = 0 l = len(lis) for n in range(1, l+1): for s in every_slice(lis, n): sm = sum(s) if sm > m: m = sm return m def every_slice(lis, n): l = len(lis) for i in range(l-n+1): yield lis[i:i+n] while True: n = int(sys.stdin.readline()) if n == 0: break lis = [] for i in range(n): lis.append(int(sys.stdin.readline())) print max_sum_seq(lis)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s508065091
p00022
Time Limit Exceeded
import sys def max_sum_seq(lis): m = 0 lis = compress(lis) l = len(lis) for n in range(1, l+1): for s in every_slice(lis, n): sm = sum(s) if sm > m: m = sm return m def every_slice(lis, n): l = len(lis) for i in range(l-n+1): yield lis[i:i+n] def compress(tmp_lst): lim = len(tmp_lst) lst = [] index = 0 while index < lim: tmp = tmp_lst[index] index += 1 while tmp > 0 and index < lim and tmp * tmp_lst[index] > 0: tmp += tmp_lst[index] index += 1 lst.append(tmp) return lst while True: n = int(sys.stdin.readline()) if n == 0: break lis = [] for i in range(n): lis.append(int(sys.stdin.readline())) print max_sum_seq(lis)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s822257277
p00022
Time Limit Exceeded
while True: n = input() if n==0: break s=[] x=[] for i in range(n): x.append(input()) for i in range(n): for j in range(i,n): s.append(sum(x[i:j+1])) print max(s)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s965729835
p00022
Time Limit Exceeded
while True: n = int(raw_input()) if n == 0: break a = [0] * n for i in range(n): a[i] = int(raw_input()) r = a[0] for i in range(n+1): for j in range(i+1, n+1): r = max(r, sum(a[i:j])) print r
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s363880188
p00022
Time Limit Exceeded
#!/usr/bin/python # -*- coding: utf-8 -*- def main(): while True: terms = int(raw_input()) if terms == 0: break data = [] for i in xrange(terms): data.append(int(raw_input())) print(max_sum_sequence(data)) def max_sum_sequence(data): max = 0 num_data = len(data) for l in xrange(num_data + 1): sum = max_at_length(data, l) if sum > max: max = sum return max def max_at_length(data, length): max = 0 num_data = len(data) for begin in xrange(num_data): sum = 0 for i in xrange(begin, begin + length): if i >= num_data: continue sum += data[i] if sum > max: max = sum return max main()
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s388065240
p00022
Time Limit Exceeded
n = int(raw_input()) ans = [] while n > 0: a = [] for i in range(n): a.append(int(raw_input())) max_sum = -100000*len(a) for i in range(len(a)): for j in range(i+1, len(a)): part_sum = sum(a[i:j]) if part_sum > max_sum: max_sum = part_sum print max_sum n = int(raw_input())
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s155451791
p00022
Time Limit Exceeded
n = int(raw_input()) ans = [] while n > 0: a = [] for i in range(n): a.append(int(raw_input())) len_a = len(a) max_sum = -100000*len_a for i in range(len_a + 1): for j in range(i+1, len_a + 1): part_sum = sum(a[i:j]) if part_sum > max_sum: max_sum = part_sum print max_sum n = int(raw_input())
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s077509521
p00022
Memory Limit Exceeded
#! /usr/bin/env python # -*- coding: utf-8 -*- import os import sys class Hoge(object): def __init__(self): pass def func(self): ''' insert your code ''' while True: n = input() if n == 0: break num = [input() for i in range(n)] s = [[0 for i in range(5001)] for j in range(5001)] for i in range(n): s[i][0] = num[i] for j in range(1, n-i): s[i][j] += s[i][j-1] + num[i+j] # for i in range(10): # for j in range(10): # print s[i][j] # print m = -float('inf') for i in range(n): for j in range(n): m = max(m, s[i][j]) print m return None if __name__ == '__main__': h = Hoge() h.func()
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s897227555
p00022
Memory Limit Exceeded
#! /usr/bin/env python # -*- coding: utf-8 -*- import os import sys class Hoge(object): def __init__(self): pass def func(self): ''' insert your code ''' while True: n = input() if n == 0: break num = [input() for i in range(n)] s = [[-float('inf') for i in range(n+1)] for j in range(n+1)] for i in range(n): s[i][0] = num[i] for j in range(1, n-i): s[i][j] += s[i][j-1] + num[i+j] # for i in range(10): # for j in range(10): # print s[i][j] # print m = -float('inf') for i in range(n): for j in range(n): m = max(m, s[i][j]) print m return None if __name__ == '__main__': h = Hoge() h.func()
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s198124396
p00022
Memory Limit Exceeded
def inc(x): return x+1 while True: n = int(raw_input()) if n == 0: break numbers = [int(raw_input()) for i in range(n)] if max(numbers) <= 0: print max(numbers) else: pointers = filter(lambda x:x[0]<x[1], map(lambda x:(x/n,x%n+1),xrange(n*n))) print max(map(lambda x:reduce(lambda y,z:y+z,numbers[x[0]:x[1]]),pointers))
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s896850518
p00022
Memory Limit Exceeded
def inc(x): return x+1 while True: n = int(raw_input()) if n == 0: break numbers = [int(raw_input()) for i in range(n)] if max(numbers) <= 0: print max(numbers) else: print max(map(lambda x:reduce(lambda y,z:y+z,numbers[x[0]:x[1]]),filter(lambda x:x[0]<x[1], map(lambda x:(x/n,x%n+1),xrange(n*n)))))
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s085633719
p00022
Memory Limit Exceeded
def inc(x): return x+1 while True: n = int(raw_input()) if n == 0: break numbers = [int(raw_input()) for i in range(n)] pointers = filter(lambda x:x[0]<x[1], map(lambda x:(x/n,x%n+1),xrange(n*n))) ans = 0 for pointer in pointers: tmp = reduce(lambda x,y:x+y,numbers[pointer[0]:pointer[1]]) ans = tmp > ans if tmp else ans print ans
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s817562409
p00022
Memory Limit Exceeded
def inc(x): return x+1 while True: n = int(raw_input()) if n == 0: break numbers = [int(raw_input()) for i in range(n)] pointers = filter(lambda x:x[0]<x[1], map(lambda x:(x/n,x%n+1),xrange(n*n))) ans = 0 for pointer in pointers: tmp = reduce(lambda x,y:x+y,numbers[pointer[0]:pointer[1]]) ans = tmp > ans if tmp else ans del pointer print ans del numbers del pointers
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s471548248
p00022
Memory Limit Exceeded
import sys def max_sum_seq(lis): r = [] l = len(lis) for n in range(1, l+1): r = r + every_slice(lis, n) return max(map((lambda r1: reduce((lambda x, y: x + y), r1, 0)), r)) def every_slice(lis, n): r = [] l = len(lis) for i in range(l-n+1): r.append(lis[i:i+n]) return r #input_file = open(sys.argv[1], "r") while True: # n = int(input_file.readline()) n = int(sys.stdin.readline()) if n == 0: break lis = [] for i in range(n): lis.append(int(sys.stdin.readline())) print max_sum_seq(lis)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s546492824
p00022
Accepted
while 1: n=int(input()) if n==0:break nlist=[] nans=-100001 for i in range(n): nlist.append(int(input())) nkeep=0 for i in nlist: if nkeep<0: nkeep=i else: nkeep+=i if nans<nkeep:nans=nkeep if max(nlist)<0:nans=max(nlist) print(nans)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s395291099
p00022
Accepted
while True: N=int(input()) if N==0: break num=0 res=-11111111 for i in range(N): a=int(input()) num=max(num+a, a) #print(num) res=max(num, res) #print(res) print(res)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s275288565
p00022
Accepted
#!/usr/bin/env python # -*- coding: utf-8 -*- while True: num = input() if num == 0: break lis = [0]*num for i in range(num): n = input() if i == 0: lis[0] = n else: lis[i] = max( lis[i-1] + n , n ) print max(lis)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s230619845
p00022
Accepted
while True: n = int(raw_input()) if n == 0: break a=[] for i in range(n): a.append(int(raw_input())) max = -1e10 for i in range(len(a)): sum = 0 for j in range(i,len(a)): sum += a[j] if sum > max: max = sum print max
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s704650202
p00022
Accepted
#!/usr/bin/env python # -*- coding: utf-8 -*- while True: n = int(input()) if n == 0: break a = [] for i in range(0,n): a.append(int(input())) sumMax = -100000 for i in range(0,n): tmp = 0 for j in range(i,n): tmp += a[j] sumMax = max(sumMax,tmp) print(sumMax)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s636158077
p00022
Accepted
while True: n=int(input()) if n==0: break a=[] for i in range(n): a.append(int(input())) for i in range(1,n): a[i]=max(a[i-1]+a[i],a[i]) print(max(a))
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s009802789
p00022
Accepted
import sys f = sys.stdin while True: n = int(f.readline()) if n == 0: break a = [int(f.readline()) for i in range(n)] sum_max = now = 0 for ai in a: now = max(0, now + ai) sum_max = max(sum_max, now) print(sum_max if sum_max else max(a))
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s603193025
p00022
Accepted
while True: n=int(input()) if n == 0: break ans=-1e100 l=[] for _ in range(n): l.append(int(input())) for i in range(n): s=0 for j in range(i,n): s+=l[j] if ans < s: ans = s print(ans)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s413367097
p00022
Accepted
while True: sequence = [] n = input() if n ==0: break for i in range(n): sequence.append(int(raw_input())) max_sum=-100000 sum=0 while len(sequence)!=0: sum+=sequence.pop(0) if max_sum<sum: max_sum=sum if sum<0: sum=0 print max_sum
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s945943936
p00022
Accepted
while True: n = int(input()) if n == 0: break s = [0] for i in range(n): s.append(int(input()) + s[i]) m = -100000 * 5000 for i in range(0, n): for j in range(i + 1, n + 1): m = max(m, s[j] - s[i]) print(m)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s373140197
p00022
Accepted
while 1: n=input() if n==0:break m=0 r=-1e5 for x in[input()for i in range(n)]: m=max(m,0)+x r=max(m,r) print r
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s145768713
p00022
Accepted
while 1: n=input() if n==0:break m=0 r=-1e5 for x in[input()for i in xrange(n)]: m=max(m,0)+x r=max(m,r) print r
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s865348907
p00022
Accepted
while 1: n=input() if n==0:break m=0 r=[-10**5]*n for x in[input()for i in range(n)]: m=max(m,0)+x r.append(m) print max(r)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s108710604
p00022
Accepted
while 1: n=input() if n==0:break r=[input()for i in range(n)] for i in range(1,n): r[i]=max(r[i-1]+r[i],r[i]) print max(r)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s486892717
p00022
Accepted
while 1: n=input() if n==0:break r=[input()for i in xrange(n)] #print r for i in xrange(1,n): r[i]=max(r[i-1]+r[i],r[i]) #print r print max(r)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s130928034
p00022
Accepted
while 1: n=input() if n==0:break r=[int(raw_input())for i in range(n)] for i in range(1,n): r[i]=max(r[i-1]+r[i],r[i]) print max(r)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s831725593
p00022
Accepted
while 1: n = int(input()) if n == 0: break a = [] for _ in range(n): a.append(int(input())) dp = [] dp.append(a[0]) for i in range(1,len(a)): dp.append(max(dp[i-1] + a[i], a[i])) print(max(dp))
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s923405856
p00022
Accepted
while True: n = int(input()) if n == 0: break res = -1111111111 s = 0 for i in range(n): a = int(input()) s = max(s + a, a) res = max(s, res) print(res)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s563770336
p00022
Accepted
while True: N = int(raw_input()) if N == 0: break L = map(int, [raw_input() for _ in range(N)]) maxi = max(L) for i in range(N): if L[i] <= 0: continue tot = L[i] for j in range(1, N - i): tot += L[i + j] if tot > maxi: maxi = tot print maxi
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s939873093
p00022
Accepted
while 1: n=int(raw_input()) if n==0: break a,dp=[],[] for i in range(n): a.append(int(raw_input())) ans=a[0] for i in range(n): tmp=0 for j in range(i,n): tmp+=a[j] ans=max(ans,tmp) print ans
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s242437737
p00022
Accepted
while True: n = int(input()) if n == 0: break a = 0 max_c = -200000 while n > 0: i = int(input()) a += i if max_c < a: max_c = a if a <= 0: a = 0 n -= 1 print(max_c)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s513589858
p00022
Accepted
from math import * PI = 3.1415926535898 while True: try: n = input() if n == 0: break res = [] arr = [] su = 0 for i in range(n): arr.append(input()) res.append(arr[0]) ans = arr[0] for i in range(1, n): res.append(max(res[i-1] + arr[i], arr[i])) ans = max(ans, res[i]) print ans except EOFError: break
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s090493823
p00022
Accepted
while True: num = int(input()) if not num: break result, tmp = -1e6, 0 for _ in range(num): new = int(input()) tmp = max(new, new+tmp) result = max(tmp, result) print(result)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s546092748
p00022
Accepted
while True: n = int(input()) if not n: break a = [0] * n a[0] = int(input()) for i in range(1, n): an = int(input()) a[i] = max(an, a[i - 1] + an) print(max(a))
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s340896758
p00022
Accepted
import itertools while True: n = int(input()) if n == 0: break else: a = [int(input()) for i in range(n)] a = list(itertools.accumulate(a)) a.insert(0, 0) ans = -100000 for j in range(n): for k in range(j + 1, n + 1): ans = max(ans, a[k] - a[j]) print(ans)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s830464009
p00022
Accepted
while True: n = int(input()) if n == 0: break else: a = [int(input()) for i in range(n)] for i in range(1, n): a[i] = max(a[i - 1] + a[i], a[i]) print(max(a))
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s764463657
p00022
Accepted
while True: n = int(input()) if n == 0: break dp = [-1e6] for i in range(n): a = int(input()) dp.append(max(dp[i] + a, a)) print(max(dp))
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s919856206
p00022
Accepted
while True: n=int(input()) if n==0: break A=[] for i in range(n): x=int(input()) A.append(x) B=[int()]*n B[0]=A[0] for i in range(1,n): if A[i]>=A[i]+B[i-1]: B[i]=A[i] else: B[i]=A[i]+B[i-1] print(max(B))
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s631322488
p00022
Accepted
while True: n = input() if n == 0: break a = [ input() for i in xrange(n) ] m = -100000 for i in xrange(n): s = 0 for j in xrange(i, n): s += a[j] m = max(m, s) print m
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s689488343
p00022
Accepted
# -*- coding: utf-8 -*- while True: n = int(raw_input()) if n == 0: break A = [int(raw_input()) for i in range(n)] sum = [[0 for i in range(n)] for j in range(n)] sum[0][0] = Max = A[0] for i in range(1, n): sum[0][i] = sum[0][i-1] + A[i] Max = max(Max, sum[0][i]) for i in range(1, n): for j in range(i, n): sum[i][j] = sum[i][j-1] + A[j] Max = max(Max, sum[i][j]) print Max
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s420211351
p00022
Accepted
def maxsum(A): smax = A[0] ssum = max(A[0], 0) for a in A[1:]: ssum += a smax = max(ssum, smax) ssum = max(ssum, 0) return smax while True: n = int(input()) if not n: break A = [] for i in range(n): a = int(input()) A.append(a) print(maxsum(A))
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s303103207
p00022
Accepted
while 1: n = int(input()) if n == 0: break m = [None] * n t = [None] * n for i in range(n): a = int(input()) m[i] = t[i] = a for j in range(i): t[j] += a m[j] = max(m[j], t[j]) print(max(m))
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s930966343
p00022
Accepted
import sys for i in sys.stdin: n = int(i) if n == 0: break max = -100000 sum = int(input()) for i in range(n-1): m = int(input()) if sum < 0 and sum < m: sum = m elif m < 0 and max < sum: max = sum sum += m else: sum += m if sum > max: max = sum print(max)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s595366720
p00022
Accepted
import sys s = "" for i in sys.stdin: n = int(i) if n == 0: break max = -100000 sum = int(input()) for i in range(n-1): m = int(input()) if sum < 0 and sum < m: sum = m else: if m < 0 and max < sum: max = sum sum += m if sum > max: s += str(sum) + "\n" else: s += str(max) + "\n" print(s,end="")
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s686578471
p00022
Accepted
while 1: n=input() if n==0:break a=[int(raw_input()) for _ in xrange(n)] wa=[0]*(n+1) max_a=-1000000 for i in xrange(n): wa[i+1]=a[i]+wa[i] for i in xrange(n): for j in xrange(i+1,n+1): if max_a<wa[j]-wa[i]: max_a=wa[j]-wa[i] print(max_a)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s346979220
p00022
Accepted
while True: n = int(input()) if n == 0: break l = [] for _ in range(n): l.append(int(input())) sum = 0 sums = [0] for i in range(n): sum += l[i] sums.append(sum) maximum_sum = -99999999999999 for e in range(1, n+1): for s in range(1, e+1): sum = sums[e] - sums[s-1] if maximum_sum < sum: maximum_sum = sum print(maximum_sum)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s849639573
p00022
Accepted
import itertools while True: n = int(input()) if n == 0: break a = [int(input()) for _ in range(n)] a[:0] = [0] for i in range(1, len(a)): a[i] += a[i - 1] print(max(map(lambda x:x[1] - x[0], itertools.combinations(a, 2))))
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s474073786
p00022
Accepted
while True: n = int(input()) if not n: break a = [int(input()) for _ in range(n)] for i in range(1, n): if a[i - 1] > 0: a[i] += a[i - 1] print(max(a))
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s215708591
p00022
Accepted
while True: n = int(input()) if n == 0: break dp = [-100000] for i in range(n): a = int(input()) dp.append(max(dp[i] + a, a)) print(max(dp))
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s549890932
p00022
Accepted
while 1: n = input() if n == 0: break sums = [-100000] for i in xrange(n): num = input() sums.append(max(sums[-1] + num, num)) print max(sums)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s061365714
p00022
Accepted
while True: N = int(input()) if N == 0: break A = [int(input()) for i in range(N)] ans = A [0] cur = 0 for i in A: cur = max(cur + i,i) ans = max(ans,cur) print(ans)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s831822783
p00022
Accepted
while True: n = input() if n == 0: exit() A = [int(raw_input()) for _ in xrange(n)] if all(a <= 0 for a in A): print max(A) continue r = 0 tmp = 0 ans = 0 while r < n: tmp += A[r] if tmp < 0: l = r tmp = 0 else: ans = max(ans, tmp) r += 1 print ans
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s563649753
p00022
Accepted
while 1: n = int(input()) if n == 0: break ans = -1000000000 a = [0] for i in range(n): a.append(int(input())) # a = [input() for i in range(n)] a[i+1] += a[i] for j in range(0,i+1): ans = max(ans, a[i+1]-a[j]) print(ans)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s149716571
p00022
Accepted
while True: n = int(input()) if n == 0: break else: A = [] Sum = [] for i in range(n): A.append(int(input())) Wa = 0 for i in range(0,n): Wa += A[i] Sum.append(Wa) for i in range(0 , n): for j in range(0 , i): Num = Sum[i] - Sum[j] Sum.append(Num) print(max(Sum))
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s559884937
p00022
Accepted
n=int(input()) while(n!=0): list=[] list.append(int(input())) for i in range(1,n): num=int(input()) list.append(max(num,num+list[i-1])) print(max(list)) n=int(input())
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s155424244
p00022
Accepted
if __name__ == '__main__': while True: # ??????????????\??? loop = int(input()) if loop == 0: break data = [int(input()) for _ in range(loop)] # ??????????????? max_total = max(data) # ??£?¶?????????°???????????§????¨???? total = 0 for d in data: if d > 0: # ??°??????+??§????????°?????±????°???? total += d # ????¨?????¶???????????¨?????????´??°????????????????¢???????????????? if total > max_total: max_total = total else: # ??°??????-?????´?????????????????§????????£???????????????????????§?????????????????? if total > abs(d): # ???????????§??????????????????????????§????????°???total???????????????????¶??¶??????? total += d # ???????????????????????????????????§???max_total?????´??°??????????????§????????? else: total = 0 # ???????????????????????§??????????????????????????§??????????????§????¨??????????????????????????¬?????????????????????????????????? # ???????????¨??? print(max_total)
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>
s117361345
p00022
Accepted
import sys while True: n = sys.stdin.readline() if n == "0\n": break n = int(n) l = [] for i in range(n): l.append(int(raw_input().rstrip())) max_sum=-100000000 for i in range(-1, n): sm = 0 for j in range(i+1, n): sm += l[j] if max_sum < sm: max_sum = sm print max_sum
7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0
19 14 1001
<H1>Maximum Sum Sequence</H1> <p> Given a sequence of numbers <var>a<sub>1</sub></var>, <var>a<sub>2</sub></var>, <var>a<sub>3</sub></var>, ..., <var>a<sub>n</sub></var>, find the maximum sum of a contiguous subsequence of those numbers. Note that, a subsequence of one element is also a <i>contiquous</i> subsequence. </p> <H2>Input</H2> <p> The input consists of multiple datasets. Each data set consists of: <pre> <var>n</var> <var>a<sub>1</sub></var> <var>a<sub>2</sub></var> . . <var>a<sub>n</sub></var> </pre> <p> You can assume that 1 &le; <var>n</var> &le; 5000 and -100000 &le; <var>a<sub>i</sub></var> &le; 100000. </p> <p> The input end with a line consisting of a single 0. </p> <H2>Output</H2> <p> For each dataset, print the maximum sum in a line. </p> <H2>Sample Input</H2> <pre> 7 -5 -1 6 4 9 -6 -7 13 1 2 3 2 -2 -1 1 2 3 2 1 -2 1 3 1000 -200 201 0 </pre> <H2>Output for the Sample Input</H2> <pre> 19 14 1001 </pre>