s_id
stringlengths 10
10
| p_id
stringlengths 6
6
| u_id
stringlengths 10
10
| date
stringlengths 10
10
| language
stringclasses 1
value | original_language
stringclasses 11
values | filename_ext
stringclasses 1
value | status
stringclasses 1
value | cpu_time
int64 0
100
| memory
stringlengths 4
6
| code_size
int64 15
14.7k
| code
stringlengths 15
14.7k
| problem_id
stringlengths 6
6
| problem_description
stringlengths 358
9.83k
| input
stringlengths 2
4.87k
| output
stringclasses 807
values | __index_level_0__
int64 1.1k
1.22M
|
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
s517837582
|
p00021
|
u912237403
|
1394223031
|
Python
|
Python
|
py
|
Accepted
| 10
|
4360
| 156
|
import math
for i in range(int(raw_input())):
a,w,b,x,c,y,d,z=map(float, raw_input().split())
print ["NO","YES"][abs((w-x)*(c-d)-(y-z)*(a-b))<1e-10]
|
p00021
|
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>Parallelism</H1>
<p>
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "<span>YES</span>" and if not prints "<span>NO</span>".
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:<br/>
<br/>
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$<br/>
</p>
<p>
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$.
Each value is a real number with at most 5 digits after the decimal point.
</p>
<H2>Output</H2>
<p>
For each dataset, print "<span>YES</span>" or "<span>NO</span>" in a line.
</p>
<H2>Sample Input</H2>
<pre>
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
</pre>
|
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
|
YES
NO
| 7,402
|
s731217604
|
p00021
|
u491763171
|
1401139355
|
Python
|
Python
|
py
|
Accepted
| 10
|
4236
| 317
|
n = input()
for i in xrange(n):
x1, y1, x2, y2, x3, y3, x4, y4 = map(float, raw_input().split())
Ax = x1 - x2
Ay = y1 - y2
Bx = x3 - x4
By = y3 - y4
if Ax == Bx == 0 or Ay == By == 0:
print "YES"
elif abs(Ay * Bx - By * Ax) < 1e-10:
print "YES"
else:
print "NO"
|
p00021
|
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>Parallelism</H1>
<p>
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "<span>YES</span>" and if not prints "<span>NO</span>".
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:<br/>
<br/>
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$<br/>
</p>
<p>
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$.
Each value is a real number with at most 5 digits after the decimal point.
</p>
<H2>Output</H2>
<p>
For each dataset, print "<span>YES</span>" or "<span>NO</span>" in a line.
</p>
<H2>Sample Input</H2>
<pre>
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
</pre>
|
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
|
YES
NO
| 7,403
|
s274804603
|
p00021
|
u436634575
|
1401142983
|
Python
|
Python3
|
py
|
Accepted
| 30
|
6744
| 185
|
n = int(input())
for i in range(n):
x1, y1, x2, y2, x3, y3, x4, y4 = map(float, input().split())
print('YES' if abs((x2 - x1)*(y4 - y3) - (x4 - x3)*(y2 - y1)) < 1e-10 else 'NO')
|
p00021
|
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>Parallelism</H1>
<p>
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "<span>YES</span>" and if not prints "<span>NO</span>".
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:<br/>
<br/>
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$<br/>
</p>
<p>
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$.
Each value is a real number with at most 5 digits after the decimal point.
</p>
<H2>Output</H2>
<p>
For each dataset, print "<span>YES</span>" or "<span>NO</span>" in a line.
</p>
<H2>Sample Input</H2>
<pre>
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
</pre>
|
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
|
YES
NO
| 7,404
|
s485761665
|
p00021
|
u557208833
|
1402209471
|
Python
|
Python
|
py
|
Accepted
| 10
|
4392
| 381
|
import math
DELTA = 1e-10
def readnums():
return raw_input().split()
def cross(v1,v2):
return v1[0]*v2[1]-v1[1]*v2[0]
[n] = readnums()
for i in range(0,int(n)):
[xa,ya,xb,yb,xc,yc,xd,yd] = map(float,readnums())
vab = (xb-xa,yb-ya)
vcd = (xd-xc,yd-yc)
prod = cross(vab,vcd)
if math.fabs(prod) < DELTA:
print "YES"
else:
print "NO"
|
p00021
|
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>Parallelism</H1>
<p>
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "<span>YES</span>" and if not prints "<span>NO</span>".
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:<br/>
<br/>
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$<br/>
</p>
<p>
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$.
Each value is a real number with at most 5 digits after the decimal point.
</p>
<H2>Output</H2>
<p>
For each dataset, print "<span>YES</span>" or "<span>NO</span>" in a line.
</p>
<H2>Sample Input</H2>
<pre>
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
</pre>
|
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
|
YES
NO
| 7,405
|
s964401687
|
p00021
|
u187074069
|
1594902198
|
Python
|
Python3
|
py
|
Accepted
| 20
|
5616
| 376
|
num = int(input())
l = []
for i in range(num):
lst = list(map(float, input().split()))
x1, y1 = lst[0], lst[1]
x2, y2 = lst[2], lst[3]
x3, y3 = lst[4], lst[5]
x4, y4 = lst[6], lst[7]
d = (x2 - x1) * (y4 - y3) - (x4 - x3) * (y2 - y1)
k = abs(d)
if k <= 1e-11:
l.append('YES')
else:
l.append('NO')
for i in l:
print(i)
|
p00021
|
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>Parallelism</H1>
<p>
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "<span>YES</span>" and if not prints "<span>NO</span>".
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:<br/>
<br/>
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$<br/>
</p>
<p>
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$.
Each value is a real number with at most 5 digits after the decimal point.
</p>
<H2>Output</H2>
<p>
For each dataset, print "<span>YES</span>" or "<span>NO</span>" in a line.
</p>
<H2>Sample Input</H2>
<pre>
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
</pre>
|
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
|
YES
NO
| 7,406
|
s889770793
|
p00021
|
u903393228
|
1594628969
|
Python
|
Python3
|
py
|
Accepted
| 30
|
5616
| 776
|
def cross_product(a,b):
return (a.conjugate()*b).imag
n = int(input())
for i in range(n):
A = list(input().split())
B = []
for i in A:
#print(i)
if '.' not in i:
#print('you',i)
j = int(i)*(10**5)
elif '-' not in i:
#print('meiyou',i)
p,q = i.split('.')
j = int(p)*(10**5)+int(q)*10**(5-len(q))
else:
#print('youmeiyou',i)
p,q = i.split('.')
j = int(p)*(10**5)-int(q)*10**(5-len(q))
#print(j)
B.append(j)
#print(B)
u = complex(B[2]-B[0],B[3]-B[1])
v = complex(B[6]-B[4],B[7]-B[5])
#print(abs(cross_product(u,v)))
if abs(cross_product(u,v)) == 0:
print('YES')
else:
print('NO')
|
p00021
|
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>Parallelism</H1>
<p>
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "<span>YES</span>" and if not prints "<span>NO</span>".
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:<br/>
<br/>
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$<br/>
</p>
<p>
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$.
Each value is a real number with at most 5 digits after the decimal point.
</p>
<H2>Output</H2>
<p>
For each dataset, print "<span>YES</span>" or "<span>NO</span>" in a line.
</p>
<H2>Sample Input</H2>
<pre>
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
</pre>
|
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
|
YES
NO
| 7,407
|
s041757100
|
p00021
|
u913305001
|
1594444967
|
Python
|
Python3
|
py
|
Accepted
| 20
|
5604
| 150
|
N = int(input())
for _ in range(N):
a,e,b,f,c,g,d,h=map(float,input().split())
print("YES" if abs((b-a)*(h-g)-(d-c)*(f-e)) < 1e-10 else "NO")
|
p00021
|
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>Parallelism</H1>
<p>
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "<span>YES</span>" and if not prints "<span>NO</span>".
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:<br/>
<br/>
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$<br/>
</p>
<p>
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$.
Each value is a real number with at most 5 digits after the decimal point.
</p>
<H2>Output</H2>
<p>
For each dataset, print "<span>YES</span>" or "<span>NO</span>" in a line.
</p>
<H2>Sample Input</H2>
<pre>
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
</pre>
|
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
|
YES
NO
| 7,408
|
s123297418
|
p00021
|
u742290340
|
1594027988
|
Python
|
Python3
|
py
|
Accepted
| 20
|
5624
| 240
|
N = int(input())
for _ in range(N):
P = list(map(float,input().split()))
a, b, c, d = [complex(P[i*2],P[i*2+1])*1000000 for i in range(4)]
parallel = ((a-b).conjugate() *(c-d)).imag ==0
print("YES" if parallel else "NO")
|
p00021
|
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>Parallelism</H1>
<p>
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "<span>YES</span>" and if not prints "<span>NO</span>".
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:<br/>
<br/>
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$<br/>
</p>
<p>
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$.
Each value is a real number with at most 5 digits after the decimal point.
</p>
<H2>Output</H2>
<p>
For each dataset, print "<span>YES</span>" or "<span>NO</span>" in a line.
</p>
<H2>Sample Input</H2>
<pre>
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
</pre>
|
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
|
YES
NO
| 7,409
|
s352655272
|
p00021
|
u515473089
|
1594025343
|
Python
|
Python3
|
py
|
Accepted
| 30
|
5748
| 349
|
import math
import cmath
def dot(a:complex,b:complex):
return (a.conjugate()*b).real
def cross(a:complex,b:complex):
return (a.conjugate()*b).imag
eps=10**(-11)
n=int(input())
for i in range(n):
l=list(map(float,input().split()))
p=[complex(l[2*j],l[2*j+1]) for j in range(4)]
print('YES' if abs(cross(p[1]-p[0],p[3]-p[2]))<eps else 'NO')
|
p00021
|
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>Parallelism</H1>
<p>
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "<span>YES</span>" and if not prints "<span>NO</span>".
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:<br/>
<br/>
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$<br/>
</p>
<p>
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$.
Each value is a real number with at most 5 digits after the decimal point.
</p>
<H2>Output</H2>
<p>
For each dataset, print "<span>YES</span>" or "<span>NO</span>" in a line.
</p>
<H2>Sample Input</H2>
<pre>
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
</pre>
|
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
|
YES
NO
| 7,410
|
s675053232
|
p00021
|
u260980560
|
1588731750
|
Python
|
Python3
|
py
|
Accepted
| 20
|
5612
| 205
|
N = int(input())
for i in range(N):
x1, y1, x2, y2, x3, y3, x4, y4 = map(float, input().split())
x2 -= x1; y2 -= y1
x4 -= x3; y4 -= y3
print("YES" if abs(x2*y4 - x4*y2) < 1e-10 else "NO")
|
p00021
|
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>Parallelism</H1>
<p>
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "<span>YES</span>" and if not prints "<span>NO</span>".
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:<br/>
<br/>
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$<br/>
</p>
<p>
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$.
Each value is a real number with at most 5 digits after the decimal point.
</p>
<H2>Output</H2>
<p>
For each dataset, print "<span>YES</span>" or "<span>NO</span>" in a line.
</p>
<H2>Sample Input</H2>
<pre>
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
</pre>
|
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
|
YES
NO
| 7,411
|
s112152519
|
p00021
|
u808372529
|
1584063899
|
Python
|
Python3
|
py
|
Accepted
| 20
|
5628
| 207
|
n = int(input())
s1 = 0
s2 = 0
for i in range(n):
x1, y1, x2, y2, x3, y3, x4, y4 = map(float,input().split())
if abs((x2-x1)*(y4-y3)-(x4-x3)*(y2-y1)) <= 10**(-10): print("YES")
else: print("NO")
|
p00021
|
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>Parallelism</H1>
<p>
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "<span>YES</span>" and if not prints "<span>NO</span>".
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:<br/>
<br/>
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$<br/>
</p>
<p>
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$.
Each value is a real number with at most 5 digits after the decimal point.
</p>
<H2>Output</H2>
<p>
For each dataset, print "<span>YES</span>" or "<span>NO</span>" in a line.
</p>
<H2>Sample Input</H2>
<pre>
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
</pre>
|
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
|
YES
NO
| 7,412
|
s842928571
|
p00021
|
u350155409
|
1575088436
|
Python
|
Python3
|
py
|
Accepted
| 20
|
5624
| 246
|
n = int(input())
for i in range(n):
x1,y1,x2,y2,x3,y3,x4,y4 = [ float(s) for s in input().split() ]
diff = (x2-x1)*(y4-y3) - (x4-x3)*(y2-y1)
if diff < 1e-10 and diff > -1*(1e-10):
print('YES')
else:
print('NO')
|
p00021
|
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>Parallelism</H1>
<p>
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "<span>YES</span>" and if not prints "<span>NO</span>".
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:<br/>
<br/>
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$<br/>
</p>
<p>
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$.
Each value is a real number with at most 5 digits after the decimal point.
</p>
<H2>Output</H2>
<p>
For each dataset, print "<span>YES</span>" or "<span>NO</span>" in a line.
</p>
<H2>Sample Input</H2>
<pre>
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
</pre>
|
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
|
YES
NO
| 7,413
|
s506218964
|
p00021
|
u803862921
|
1571456814
|
Python
|
Python3
|
py
|
Accepted
| 20
|
5612
| 388
|
num = int(input())
EPS = 0.00000000001
for _ in range(num):
x1, y1, x2, y2, x3, y3, x4, y4 = [float(x) for x in input().split()]
abx = x2 - x1
aby = y2 - y1
cdx = x4 - x3
cdy = y4 - y3
# abx : aby = cdx : cdy
# aby * cdx - abx * cdy = 0 ( < EPSilon)
if abs(aby * cdx - abx * cdy) < EPS:
print("YES")
else:
print("NO")
|
p00021
|
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>Parallelism</H1>
<p>
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "<span>YES</span>" and if not prints "<span>NO</span>".
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:<br/>
<br/>
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$<br/>
</p>
<p>
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$.
Each value is a real number with at most 5 digits after the decimal point.
</p>
<H2>Output</H2>
<p>
For each dataset, print "<span>YES</span>" or "<span>NO</span>" in a line.
</p>
<H2>Sample Input</H2>
<pre>
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
</pre>
|
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
|
YES
NO
| 7,414
|
s465194507
|
p00021
|
u511231264
|
1566343186
|
Python
|
Python3
|
py
|
Accepted
| 20
|
5604
| 217
|
EPS = 1e-10
for q in range(int(input())):
l = list(map(float, input().split()))
if abs((l[3] - l[1]) * (l[6] - l[4]) - (l[7] - l[5]) * (l[2] - l[0])) < EPS:
print('YES')
else:
print('NO')
|
p00021
|
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>Parallelism</H1>
<p>
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "<span>YES</span>" and if not prints "<span>NO</span>".
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:<br/>
<br/>
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$<br/>
</p>
<p>
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$.
Each value is a real number with at most 5 digits after the decimal point.
</p>
<H2>Output</H2>
<p>
For each dataset, print "<span>YES</span>" or "<span>NO</span>" in a line.
</p>
<H2>Sample Input</H2>
<pre>
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
</pre>
|
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
|
YES
NO
| 7,415
|
s380382423
|
p00021
|
u108130680
|
1564804339
|
Python
|
Python3
|
py
|
Accepted
| 20
|
5604
| 190
|
for _ in range(int(input())):
x1,y1,x2,y2,x3,y3,x4,y4=map(float,input().split())
if abs((x2 - x1)*(y4 - y3) - (y2 - y1)*(x4 - x3)) < 1e-10:
print("YES")
else:
print("NO")
|
p00021
|
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>Parallelism</H1>
<p>
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "<span>YES</span>" and if not prints "<span>NO</span>".
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:<br/>
<br/>
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$<br/>
</p>
<p>
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$.
Each value is a real number with at most 5 digits after the decimal point.
</p>
<H2>Output</H2>
<p>
For each dataset, print "<span>YES</span>" or "<span>NO</span>" in a line.
</p>
<H2>Sample Input</H2>
<pre>
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
</pre>
|
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
|
YES
NO
| 7,416
|
s285258894
|
p00021
|
u528682978
|
1562997708
|
Python
|
Python3
|
py
|
Accepted
| 30
|
5812
| 434
|
import math
import cmath
def area(x):
theta = cmath.phase(x[1]-x[0])
C = (x[3]-x[2])*complex(math.cos(-theta),math.sin(-theta))
return C.imag
def parallel(P):
x = []
for i in range(4):
x.append(complex(P[i*2],P[i*2+1]))
return True if abs(area(x))<eps else False
n = int(input())
eps = 0.0000001
for _ in range(n):
P = list(map(float,input().split()))
print("YES" if parallel(P) else "NO")
|
p00021
|
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>Parallelism</H1>
<p>
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "<span>YES</span>" and if not prints "<span>NO</span>".
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:<br/>
<br/>
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$<br/>
</p>
<p>
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$.
Each value is a real number with at most 5 digits after the decimal point.
</p>
<H2>Output</H2>
<p>
For each dataset, print "<span>YES</span>" or "<span>NO</span>" in a line.
</p>
<H2>Sample Input</H2>
<pre>
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
</pre>
|
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
|
YES
NO
| 7,417
|
s095954164
|
p00021
|
u026821956
|
1562584823
|
Python
|
Python3
|
py
|
Accepted
| 30
|
5720
| 350
|
import math
import cmath
def cross_product(a,b):
return (a.conjugate()*b).imag
n = int(input())
for i in range(n):
L = list(map(float,input().split()))
a,b,c,d = [complex(L[j*2],L[j*2+1]) for j in range(4)]
vec_A = b-a
vec_B = d-c
if abs(cross_product(vec_A,vec_B)) < 1e-11:
print('YES')
else:
print('NO')
|
p00021
|
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>Parallelism</H1>
<p>
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "<span>YES</span>" and if not prints "<span>NO</span>".
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:<br/>
<br/>
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$<br/>
</p>
<p>
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$.
Each value is a real number with at most 5 digits after the decimal point.
</p>
<H2>Output</H2>
<p>
For each dataset, print "<span>YES</span>" or "<span>NO</span>" in a line.
</p>
<H2>Sample Input</H2>
<pre>
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
</pre>
|
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
|
YES
NO
| 7,418
|
s423228856
|
p00021
|
u481944101
|
1562584101
|
Python
|
Python3
|
py
|
Accepted
| 20
|
5628
| 206
|
N=int(input())
for _ in range(N):
p=list(map(float,input().split()))
a,b,c,d=map(lambda x:complex(*x),[p[:2],p[2:4],p[4:6],p[6:]])
print(['NO','YES'][abs(((a-b).conjugate()*(c-d)).imag)<1e-11])
|
p00021
|
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>Parallelism</H1>
<p>
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "<span>YES</span>" and if not prints "<span>NO</span>".
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:<br/>
<br/>
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$<br/>
</p>
<p>
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$.
Each value is a real number with at most 5 digits after the decimal point.
</p>
<H2>Output</H2>
<p>
For each dataset, print "<span>YES</span>" or "<span>NO</span>" in a line.
</p>
<H2>Sample Input</H2>
<pre>
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
</pre>
|
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
|
YES
NO
| 7,419
|
s696588558
|
p00021
|
u506537276
|
1560158646
|
Python
|
Python3
|
py
|
Accepted
| 20
|
5628
| 250
|
n = int(input())
for i in range(n):
x1, y1, x2, y2, x3, y3, x4, y4 = map(float, input().split())
v1x = x1 - x2
v1y = y1 - y2
v2x = x3 - x4
v2y = y3 - y4
if abs(v1x * v2y - v2x * v1y) < 10 ** -10 :
print("YES")
else:
print("NO")
|
p00021
|
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>Parallelism</H1>
<p>
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "<span>YES</span>" and if not prints "<span>NO</span>".
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:<br/>
<br/>
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$<br/>
</p>
<p>
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$.
Each value is a real number with at most 5 digits after the decimal point.
</p>
<H2>Output</H2>
<p>
For each dataset, print "<span>YES</span>" or "<span>NO</span>" in a line.
</p>
<H2>Sample Input</H2>
<pre>
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
</pre>
|
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
|
YES
NO
| 7,420
|
s850229956
|
p00021
|
u625806423
|
1557113148
|
Python
|
Python3
|
py
|
Accepted
| 20
|
5644
| 340
|
EPS = 10**-10
n = int(input())
pos = []
for _ in range(n):
pos.append(list(map(float, input().split())))
for i in range(n):
vec_ax = pos[i][2]-pos[i][0]
vec_ay = pos[i][3]-pos[i][1]
vec_bx = pos[i][6]-pos[i][4]
vec_by = pos[i][7]-pos[i][5]
if abs(vec_bx*vec_ay - vec_by*vec_ax) < EPS:
print("YES")
else:
print("NO")
|
p00021
|
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>Parallelism</H1>
<p>
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "<span>YES</span>" and if not prints "<span>NO</span>".
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:<br/>
<br/>
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$<br/>
</p>
<p>
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$.
Each value is a real number with at most 5 digits after the decimal point.
</p>
<H2>Output</H2>
<p>
For each dataset, print "<span>YES</span>" or "<span>NO</span>" in a line.
</p>
<H2>Sample Input</H2>
<pre>
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
</pre>
|
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
|
YES
NO
| 7,421
|
s547067113
|
p00021
|
u647694976
|
1555493902
|
Python
|
Python3
|
py
|
Accepted
| 20
|
5604
| 225
|
n = int(input())
for i in range(n):
x1, y1, x2, y2, x3, y3, x4, y4 = map(float, input().split())
if abs( (x2 - x1) * (y4 - y3) - (y2 - y1) * (x4 - x3) ) < 1e-10:
print('YES')
else:
print('NO')
|
p00021
|
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>Parallelism</H1>
<p>
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "<span>YES</span>" and if not prints "<span>NO</span>".
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:<br/>
<br/>
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$<br/>
</p>
<p>
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$.
Each value is a real number with at most 5 digits after the decimal point.
</p>
<H2>Output</H2>
<p>
For each dataset, print "<span>YES</span>" or "<span>NO</span>" in a line.
</p>
<H2>Sample Input</H2>
<pre>
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
</pre>
|
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
|
YES
NO
| 7,422
|
s619754681
|
p00021
|
u998437062
|
1554719542
|
Python
|
Python3
|
py
|
Accepted
| 20
|
5620
| 407
|
n = int(input())
for _ in range(n):
x1, y1, x2, y2, x3, y3, x4, y4 = map(float, input().split())
abx = x2 - x1
aby = y2 - y1
cdx = x4 - x3
cdy = y4 - y3
if abs(aby * cdx) < 1e-10 and abs(cdy * abx) < 1e-10:
print(['NO', 'YES'][abs(abx - cdx) < 1e-10 or abs(aby - cdy) < 1e-10])
elif abs(aby * cdx - cdy * abx) < 1e-10:
print('YES')
else:
print('NO')
|
p00021
|
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>Parallelism</H1>
<p>
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "<span>YES</span>" and if not prints "<span>NO</span>".
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:<br/>
<br/>
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$<br/>
</p>
<p>
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$.
Each value is a real number with at most 5 digits after the decimal point.
</p>
<H2>Output</H2>
<p>
For each dataset, print "<span>YES</span>" or "<span>NO</span>" in a line.
</p>
<H2>Sample Input</H2>
<pre>
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
</pre>
|
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
|
YES
NO
| 7,423
|
s273671745
|
p00021
|
u025180675
|
1544697798
|
Python
|
Python3
|
py
|
Accepted
| 20
|
5624
| 375
|
def cross_product(a,b):
return (a.conjugate()*b).imag
N = int(input().strip())
for _ in range(N):
P = list(map(float,input().strip().split()))
for i in range(len(P)):
P[i] = int(P[i]*1000000.0)
z = complex(P[0]-P[2],P[1]-P[3])
w = complex(P[4]-P[6],P[5]-P[7])
if abs(cross_product(z,w)) < 1:
print("YES")
else:
print("NO")
|
p00021
|
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>Parallelism</H1>
<p>
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "<span>YES</span>" and if not prints "<span>NO</span>".
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:<br/>
<br/>
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$<br/>
</p>
<p>
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$.
Each value is a real number with at most 5 digits after the decimal point.
</p>
<H2>Output</H2>
<p>
For each dataset, print "<span>YES</span>" or "<span>NO</span>" in a line.
</p>
<H2>Sample Input</H2>
<pre>
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
</pre>
|
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
|
YES
NO
| 7,424
|
s958666411
|
p00021
|
u291570764
|
1543496775
|
Python
|
Python3
|
py
|
Accepted
| 20
|
5608
| 260
|
for i in range(int(input())):
ax, ay, bx, by, cx, cy, dx, dy = map(float, input().split())
if ax==bx or cx==dx:
print("YES" if ax==bx and cx==dx and ay!=by and cy!=dy else "NO")
else:
print("YES" if abs((ay-by)/(ax-bx)-(cy-dy)/(cx-dx))<1e-10 else "NO")
|
p00021
|
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>Parallelism</H1>
<p>
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "<span>YES</span>" and if not prints "<span>NO</span>".
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:<br/>
<br/>
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$<br/>
</p>
<p>
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$.
Each value is a real number with at most 5 digits after the decimal point.
</p>
<H2>Output</H2>
<p>
For each dataset, print "<span>YES</span>" or "<span>NO</span>" in a line.
</p>
<H2>Sample Input</H2>
<pre>
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
</pre>
|
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
|
YES
NO
| 7,425
|
s377203476
|
p00021
|
u563075864
|
1542687317
|
Python
|
Python3
|
py
|
Accepted
| 20
|
5636
| 217
|
n = int(input())
E = 10**-10
for _ in range(n):
x1,y1,x2,y2,x3,y3,x4,y4 = [float(i) for i in input().split()]
if abs((x2-x1)*(y4-y3) - (y2-y1)*(x4-x3)) < E:
print("YES")
else:
print("NO")
|
p00021
|
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>Parallelism</H1>
<p>
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "<span>YES</span>" and if not prints "<span>NO</span>".
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:<br/>
<br/>
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$<br/>
</p>
<p>
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$.
Each value is a real number with at most 5 digits after the decimal point.
</p>
<H2>Output</H2>
<p>
For each dataset, print "<span>YES</span>" or "<span>NO</span>" in a line.
</p>
<H2>Sample Input</H2>
<pre>
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
</pre>
|
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
|
YES
NO
| 7,426
|
s941044904
|
p00021
|
u067299340
|
1542176243
|
Python
|
Python3
|
py
|
Accepted
| 30
|
5620
| 292
|
for i in range(int(input())):
x1, y1, x2, y2, x3, y3, x4, y4 = [float(x) for x in input().split()]
s1 = round((y2 - y1) / (x2 - x1), 10) if x1 != x2 else float('inf')
s2 = round((y4 - y3) / (x4 - x3), 10) if x3 != x4 else float('inf')
print("YES" if s1 == s2 else "NO")
|
p00021
|
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>Parallelism</H1>
<p>
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "<span>YES</span>" and if not prints "<span>NO</span>".
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:<br/>
<br/>
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$<br/>
</p>
<p>
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$.
Each value is a real number with at most 5 digits after the decimal point.
</p>
<H2>Output</H2>
<p>
For each dataset, print "<span>YES</span>" or "<span>NO</span>" in a line.
</p>
<H2>Sample Input</H2>
<pre>
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
</pre>
|
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
|
YES
NO
| 7,427
|
s181339204
|
p00021
|
u717526540
|
1541652957
|
Python
|
Python3
|
py
|
Accepted
| 30
|
5664
| 242
|
import math
n = int(input())
for _ in range(n):
x1, y1, x2, y2, x3, y3, x4, y4 = map(float, input().split())
var = abs((x2-x1) * (y4-y3) - (x4-x3) * (y2-y1))
if var < 1e-10:
print("YES")
else:
print("NO")
|
p00021
|
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>Parallelism</H1>
<p>
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "<span>YES</span>" and if not prints "<span>NO</span>".
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:<br/>
<br/>
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$<br/>
</p>
<p>
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$.
Each value is a real number with at most 5 digits after the decimal point.
</p>
<H2>Output</H2>
<p>
For each dataset, print "<span>YES</span>" or "<span>NO</span>" in a line.
</p>
<H2>Sample Input</H2>
<pre>
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
</pre>
|
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
|
YES
NO
| 7,428
|
s442440929
|
p00021
|
u536280367
|
1537799858
|
Python
|
Python3
|
py
|
Accepted
| 20
|
5604
| 339
|
for i in range(int(input())):
x1, y1, x2, y2, x3, y3, x4, y4 = map(float, input().split())
if x2 == x1 and x4 == x3:
print('YES')
continue
if x2 == x1 or x4 == x3:
print('NO')
continue
if abs((y2-y1)/(x2-x1) - (y4-y3)/(x4-x3)) < 1e-10:
print('YES')
else:
print('NO')
|
p00021
|
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>Parallelism</H1>
<p>
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "<span>YES</span>" and if not prints "<span>NO</span>".
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:<br/>
<br/>
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$<br/>
</p>
<p>
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$.
Each value is a real number with at most 5 digits after the decimal point.
</p>
<H2>Output</H2>
<p>
For each dataset, print "<span>YES</span>" or "<span>NO</span>" in a line.
</p>
<H2>Sample Input</H2>
<pre>
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
</pre>
|
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
|
YES
NO
| 7,429
|
s724403257
|
p00021
|
u219940997
|
1537453232
|
Python
|
Python3
|
py
|
Accepted
| 20
|
5616
| 259
|
n = int(input())
cordinates = [list(map(float, input().split())) for _ in range(n)]
for cod in cordinates:
x1, y1, x2, y2, x3, y3, x4, y4 = cod
if abs((x2-x1) * (y4-y3) - (y2-y1) * (x4-x3)) < 1e-10:
print('YES')
else:
print('NO')
|
p00021
|
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>Parallelism</H1>
<p>
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "<span>YES</span>" and if not prints "<span>NO</span>".
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:<br/>
<br/>
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$<br/>
</p>
<p>
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$.
Each value is a real number with at most 5 digits after the decimal point.
</p>
<H2>Output</H2>
<p>
For each dataset, print "<span>YES</span>" or "<span>NO</span>" in a line.
</p>
<H2>Sample Input</H2>
<pre>
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
</pre>
|
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
|
YES
NO
| 7,430
|
s910492294
|
p00021
|
u252700163
|
1534610465
|
Python
|
Python3
|
py
|
Accepted
| 20
|
5660
| 220
|
import math
n = int(input())
for i in range(n):
x1, y1, x2, y2, x3, y3, x4, y4 = map(float, input().split())
if abs((x2 - x1) * (y4 - y3) - (y2 - y1) * (x4 - x3)) < 1e-10:
print('YES')
else:
print('NO')
|
p00021
|
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>Parallelism</H1>
<p>
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "<span>YES</span>" and if not prints "<span>NO</span>".
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:<br/>
<br/>
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$<br/>
</p>
<p>
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$.
Each value is a real number with at most 5 digits after the decimal point.
</p>
<H2>Output</H2>
<p>
For each dataset, print "<span>YES</span>" or "<span>NO</span>" in a line.
</p>
<H2>Sample Input</H2>
<pre>
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
</pre>
|
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
|
YES
NO
| 7,431
|
s396269245
|
p00021
|
u319725914
|
1534226987
|
Python
|
Python3
|
py
|
Accepted
| 30
|
5632
| 186
|
n = int(input())
for _ in range(n):
x1,y1,x2,y2,x3,y3,x4,y4 = map(float,input().split())
if abs((x2-x1)*(y4-y3)-(x4-x3)*(y2-y1)) <= 10**(-10): print("YES")
else: print("NO")
|
p00021
|
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>Parallelism</H1>
<p>
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "<span>YES</span>" and if not prints "<span>NO</span>".
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:<br/>
<br/>
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$<br/>
</p>
<p>
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$.
Each value is a real number with at most 5 digits after the decimal point.
</p>
<H2>Output</H2>
<p>
For each dataset, print "<span>YES</span>" or "<span>NO</span>" in a line.
</p>
<H2>Sample Input</H2>
<pre>
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
</pre>
|
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
|
YES
NO
| 7,432
|
s484992752
|
p00021
|
u995990363
|
1533800127
|
Python
|
Python3
|
py
|
Accepted
| 20
|
5664
| 453
|
import math
epsilon = 1e-10
def get_grad(v1, v2):
return v1[0] * v2[1] - v1[1] * v2[0]
def run():
N = int(input())
for _ in range(N):
x1, y1, x2, y2, x3, y3, x4, y4 = map(float, input().split())
_v1 = (x2 - x1, y2 - y1)
_v2 = (x4 - x3, y4 - y3)
grad = get_grad(_v1, _v2)
if abs(grad) < epsilon:
print('YES')
else:
print('NO')
if __name__ == '__main__':
run()
|
p00021
|
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>Parallelism</H1>
<p>
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "<span>YES</span>" and if not prints "<span>NO</span>".
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:<br/>
<br/>
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$<br/>
</p>
<p>
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$.
Each value is a real number with at most 5 digits after the decimal point.
</p>
<H2>Output</H2>
<p>
For each dataset, print "<span>YES</span>" or "<span>NO</span>" in a line.
</p>
<H2>Sample Input</H2>
<pre>
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
</pre>
|
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
|
YES
NO
| 7,433
|
s224110311
|
p00021
|
u079141094
|
1467464078
|
Python
|
Python3
|
py
|
Accepted
| 30
|
7612
| 208
|
# Parallelism
for _ in range(int(input())):
x1,y1,x2,y2,x3,y3,x4,y4 = map(float, input().split())
if abs((x2-x1)*(y4-y3) - (y2-y1)*(x4-x3)) < 1e-10:
print('YES')
else:
print('NO')
|
p00021
|
<script type="text/x-mathjax-config">
MathJax.Hub.Config({ tex2jax: { inlineMath: [["$","$"], ["\\(","\\)"]], processEscapes: true }});
</script>
<script type="text/javascript" src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
</script>
<H1>Parallelism</H1>
<p>
There are four points: $A(x_1, y_1)$, $B(x_2, y_2)$, $C(x_3, y_3)$, and $D(x_4, y_4)$. Write a program which determines whether the line $AB$ and the line $CD$ are parallel. If those two lines are parallel, your program should prints "<span>YES</span>" and if not prints "<span>NO</span>".
</p>
<H2>Input</H2>
<p>
Input consists of several datasets. In the first line, you are given the number of datasets $n$ ($n \leq 100$). There will be $n$ lines where each line correspondgs to each dataset. Each dataset consists of eight real numbers:<br/>
<br/>
$x_1$ $y_1$ $x_2$ $y_2$ $x_3$ $y_3$ $x_4$ $y_4$<br/>
</p>
<p>
You can assume that $-100 \leq x_1, y_1, x_2, y_2, x_3, y_3, x_4, y_4 \leq 100$.
Each value is a real number with at most 5 digits after the decimal point.
</p>
<H2>Output</H2>
<p>
For each dataset, print "<span>YES</span>" or "<span>NO</span>" in a line.
</p>
<H2>Sample Input</H2>
<pre>
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
</pre>
<H2>Output for the Sample Input</H2>
<pre>
YES
NO
</pre>
|
2
0.0 0.0 1.0 1.0 1.0 0.0 2.0 1.0
3.0 2.0 9.0 6.0 13.0 5.0 7.0 9.0
|
YES
NO
| 7,434
|
s546492824
|
p00022
|
u990228206
|
1551343089
|
Python
|
Python3
|
py
|
Accepted
| 40
|
5636
| 326
|
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)
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,435
|
s395291099
|
p00022
|
u647694976
|
1555923351
|
Python
|
Python3
|
py
|
Accepted
| 40
|
5604
| 251
|
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)
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,436
|
s275288565
|
p00022
|
u506132575
|
1416132067
|
Python
|
Python
|
py
|
Accepted
| 50
|
4412
| 252
|
#!/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)
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,437
|
s636158077
|
p00022
|
u342537066
|
1420712819
|
Python
|
Python3
|
py
|
Accepted
| 40
|
6764
| 199
|
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))
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,438
|
s009802789
|
p00022
|
u567380442
|
1422882764
|
Python
|
Python3
|
py
|
Accepted
| 40
|
6788
| 286
|
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))
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,439
|
s413367097
|
p00022
|
u540744789
|
1426006462
|
Python
|
Python
|
py
|
Accepted
| 20
|
4404
| 348
|
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
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,440
|
s373140197
|
p00022
|
u067299340
|
1433498947
|
Python
|
Python
|
py
|
Accepted
| 40
|
4432
| 121
|
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
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,441
|
s145768713
|
p00022
|
u067299340
|
1433498970
|
Python
|
Python
|
py
|
Accepted
| 40
|
4336
| 122
|
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
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,442
|
s865348907
|
p00022
|
u067299340
|
1433499250
|
Python
|
Python
|
py
|
Accepted
| 40
|
4456
| 133
|
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)
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,443
|
s108710604
|
p00022
|
u067299340
|
1433499601
|
Python
|
Python
|
py
|
Accepted
| 40
|
4448
| 129
|
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)
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,444
|
s486892717
|
p00022
|
u067299340
|
1433499898
|
Python
|
Python
|
py
|
Accepted
| 40
|
4360
| 152
|
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)
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,445
|
s130928034
|
p00022
|
u067299340
|
1433499950
|
Python
|
Python
|
py
|
Accepted
| 20
|
4436
| 138
|
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)
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,446
|
s831725593
|
p00022
|
u379956761
|
1434986660
|
Python
|
Python3
|
py
|
Accepted
| 40
|
6860
| 251
|
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))
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,447
|
s923405856
|
p00022
|
u334031393
|
1437638694
|
Python
|
Python3
|
py
|
Accepted
| 50
|
6720
| 172
|
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)
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,448
|
s242437737
|
p00022
|
u775586391
|
1448335085
|
Python
|
Python3
|
py
|
Accepted
| 60
|
7576
| 213
|
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)
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,449
|
s513589858
|
p00022
|
u461370825
|
1449743071
|
Python
|
Python
|
py
|
Accepted
| 60
|
6528
| 338
|
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
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,450
|
s090493823
|
p00022
|
u463990569
|
1452882954
|
Python
|
Python3
|
py
|
Accepted
| 40
|
7632
| 218
|
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)
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,451
|
s546092748
|
p00022
|
u797673668
|
1456641552
|
Python
|
Python3
|
py
|
Accepted
| 40
|
7600
| 208
|
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))
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,452
|
s830464009
|
p00022
|
u777299405
|
1456650804
|
Python
|
Python3
|
py
|
Accepted
| 40
|
7728
| 214
|
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))
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,453
|
s764463657
|
p00022
|
u650459696
|
1458710604
|
Python
|
Python3
|
py
|
Accepted
| 40
|
7668
| 181
|
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))
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,454
|
s919856206
|
p00022
|
u075836834
|
1458950266
|
Python
|
Python3
|
py
|
Accepted
| 40
|
7796
| 229
|
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))
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,455
|
s420211351
|
p00022
|
u572790226
|
1460606298
|
Python
|
Python3
|
py
|
Accepted
| 40
|
7632
| 331
|
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))
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,456
|
s930966343
|
p00022
|
u935184340
|
1467126969
|
Python
|
Python3
|
py
|
Accepted
| 40
|
7564
| 381
|
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)
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,457
|
s595366720
|
p00022
|
u935184340
|
1467127264
|
Python
|
Python3
|
py
|
Accepted
| 30
|
7632
| 425
|
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="")
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,458
|
s474073786
|
p00022
|
u358919705
|
1471986442
|
Python
|
Python3
|
py
|
Accepted
| 60
|
7712
| 199
|
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))
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,459
|
s215708591
|
p00022
|
u589886885
|
1472126522
|
Python
|
Python3
|
py
|
Accepted
| 50
|
7736
| 184
|
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))
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,460
|
s549890932
|
p00022
|
u379499530
|
1473065310
|
Python
|
Python
|
py
|
Accepted
| 60
|
6376
| 178
|
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)
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,461
|
s061365714
|
p00022
|
u964040941
|
1479225794
|
Python
|
Python3
|
py
|
Accepted
| 40
|
7744
| 217
|
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)
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,462
|
s831822783
|
p00022
|
u922871577
|
1479344310
|
Python
|
Python
|
py
|
Accepted
| 20
|
6444
| 381
|
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
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,463
|
s559884937
|
p00022
|
u252368621
|
1481341120
|
Python
|
Python3
|
py
|
Accepted
| 40
|
7620
| 203
|
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())
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,464
|
s155424244
|
p00022
|
u811733736
|
1481606551
|
Python
|
Python3
|
py
|
Accepted
| 40
|
7720
| 1,210
|
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)
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,465
|
s320965266
|
p00022
|
u901080241
|
1488969708
|
Python
|
Python3
|
py
|
Accepted
| 40
|
7544
| 278
|
while True:
n = int(input())
if n==0 : break
a = []
for i in range(n):
a.append(int(input()))
maxp = -100001
maxcont = -100001
for i in range(n):
maxcont = max(a[i], maxcont + a[i])
maxp = max(maxp, maxcont)
print(maxp)
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,466
|
s683625575
|
p00022
|
u462831976
|
1492721311
|
Python
|
Python3
|
py
|
Accepted
| 40
|
7736
| 192
|
while True:
n = int(input())
if n == 0:
break
s = [int(input())]
for i in range(1, n):
a = int(input())
s.append(max(a, a + s[i - 1]))
print(max(s))
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,467
|
s535213106
|
p00022
|
u462831976
|
1492721426
|
Python
|
Python3
|
py
|
Accepted
| 50
|
7748
| 192
|
while True:
n = int(input())
if n == 0:
break
s = [int(input())]
for i in range(1, n):
a = int(input())
s.append(max(a, a + s[i - 1]))
print(max(s))
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,468
|
s097337122
|
p00022
|
u462831976
|
1492721722
|
Python
|
Python3
|
py
|
Accepted
| 40
|
7800
| 385
|
# -*- coding: utf-8 -*-
import sys
import os
def max_seq(A):
s = []
s.append(A[0])
for i in range(1, len(A)):
v = max(A[i], A[i] + s[i-1])
s.append(v)
return max(s)
while True:
s = input().strip()
if s == '0':
break
N = int(s)
A = []
for i in range(N):
v = int(input())
A.append(v)
print(max_seq(A))
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,469
|
s958759608
|
p00022
|
u119127920
|
1494412458
|
Python
|
Python3
|
py
|
Accepted
| 40
|
7832
| 471
|
def solve(a_list):
if len(list(filter(lambda x: x >= 0, a_list))) == 0:
return max(a_list)
dp = [0] * len(a_list)
dp[0] = max(0, a_list[0])
for i in range(1, len(dp)):
dp[i] = max(0, a_list[i] + dp[i - 1])
return max(dp)
def main():
while True:
n = int(input())
if n == 0:
break
a_list = [int(input()) for _ in range(n)]
print(solve(a_list))
if __name__ == '__main__':
main()
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,470
|
s346174729
|
p00022
|
u119127920
|
1494413290
|
Python
|
Python3
|
py
|
Accepted
| 40
|
7804
| 470
|
def solve(a_list):
if len(list(filter(lambda x: x >= 0, a_list))) == 0:
return max(a_list)
dp = [0] * len(a_list)
dp[0] = a_list[0]
for i in range(1, len(dp)):
dp[i] = max(a_list[i], a_list[i] + dp[i - 1])
return max(dp)
def main():
while True:
n = int(input())
if n == 0:
break
a_list = [int(input()) for _ in range(n)]
print(solve(a_list))
if __name__ == '__main__':
main()
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,471
|
s692414721
|
p00022
|
u618637847
|
1494901510
|
Python
|
Python3
|
py
|
Accepted
| 50
|
7576
| 252
|
while True:
num = int(input())
if num == 0:
break
list = []
for i in range(num):
list.append(int(input()))
for i in range(1, num):
list[i] = max(list[i - 1] + list[i], list[i])
print(max(list))
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,472
|
s828605266
|
p00022
|
u905313459
|
1496463333
|
Python
|
Python3
|
py
|
Accepted
| 30
|
7792
| 203
|
while True:
n = int(input())
if not n:
break
l = [int(input()) for j in range(n)]
s = [l[0]]
for k, v in enumerate(l[1:]):
s.append(max(v, v + s[k]))
print(max(s))
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,473
|
s990987879
|
p00022
|
u519227872
|
1497274093
|
Python
|
Python3
|
py
|
Accepted
| 30
|
7724
| 387
|
from sys import stdin
def getMax(array):
mx = mx2 = array[0]
for i in array[1:]:
mx2 = max(i, mx2 + i)
mx = max(mx, mx2)
return mx
for line in stdin:
n = int(line)
if n == 0:
break
array = []
for line in stdin:
line = int(line)
array.append(line)
if len(array) == n:
break
print(getMax(array))
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,474
|
s407978663
|
p00022
|
u236679854
|
1507672850
|
Python
|
Python3
|
py
|
Accepted
| 40
|
7556
| 278
|
while True:
n = int(input())
if n == 0:
break
max_sum = max_ending_here = int(input())
for i in range(1, n):
a = int(input())
max_ending_here = max(a, max_ending_here + a)
max_sum = max(max_sum, max_ending_here)
print(max_sum)
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,475
|
s020896341
|
p00022
|
u546285759
|
1509277220
|
Python
|
Python3
|
py
|
Accepted
| 40
|
7776
| 266
|
while True:
n = int(input())
if n == 0:
break
a = [int(input()) for _ in range(n)]
minv = tmp = 0
maxv = -500000
for i in range(n):
tmp += a[i]
maxv = max(maxv, tmp - minv)
minv = min(minv, tmp)
print(maxv)
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,476
|
s893307477
|
p00022
|
u926657458
|
1509309013
|
Python
|
Python3
|
py
|
Accepted
| 40
|
7804
| 253
|
import sys
n = int(sys.stdin.readline())
while n:
l = list()
for _ in range(n):
l.append(int(input()))
a = l.copy()
for i in range(1,n):
a[i] = max(a[i-1] + l[i], l[i])
print(max(a))
n = int(sys.stdin.readline())
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,477
|
s403880096
|
p00022
|
u203261375
|
1513085885
|
Python
|
Python3
|
py
|
Accepted
| 40
|
5640
| 265
|
while True:
n = int(input())
if n == 0:
break
dp = []
for _ in range(n):
if len(dp) == 0:
dp.append(int(input()))
else:
x = int(input())
dp.append(max(dp[-1] + x, x))
print(max(dp))
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,478
|
s738439384
|
p00022
|
u024715419
|
1515642396
|
Python
|
Python3
|
py
|
Accepted
| 40
|
5632
| 204
|
while True:
n = int(input())
if n == 0:
break
dp = [int(input())]
for i in range(1, n):
a_i = int(input())
dp.append(max(dp[i - 1] + a_i, a_i))
print(max(dp))
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,479
|
s443909071
|
p00022
|
u150984829
|
1517599218
|
Python
|
Python3
|
py
|
Accepted
| 40
|
5716
| 134
|
while 1:
n=int(input())
if n==0:break
a=[int(input())for _ in[0]*n]
for i in range(1,n):a[i]=max(a[i],a[i]+a[i-1])
print(max(a))
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,480
|
s104503036
|
p00022
|
u166871988
|
1523772407
|
Python
|
Python3
|
py
|
Accepted
| 40
|
5712
| 192
|
while True:
n=int(input())
if n==0:break
l=[int(input()) for i in range(n)]
s=0
m=0
for li in l:
s=max(0,s+li)
m=max(m,s)
print(m if m else max(l))
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,481
|
s532752154
|
p00022
|
u898097781
|
1525325517
|
Python
|
Python3
|
py
|
Accepted
| 40
|
5712
| 301
|
while(1):
N = int(input())
if N==0: break
sums = []
nums = []
s = 0
for i in range(N):
n = int(input())
nums.append(n)
s += n
if s<0: s=0
sums.append(s)
if max(nums) >= 0:
print(max(sums))
else:
print(max(nums))
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,482
|
s338937924
|
p00022
|
u847467233
|
1529130058
|
Python
|
Python3
|
py
|
Accepted
| 40
|
5680
| 268
|
# AOJ 0022 Maximum Sum Sequence
# Python3 2018.6.16 bal4u
while 1:
n = int(input())
if n == 0: break
s = [0]*5001
ans = s[0] = int(input())
for i in range(1, n):
v = int(input())
s[i] = v if s[i-1]+v < v else s[i-1]+v
if s[i] > ans: ans = s[i]
print(ans)
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,483
|
s411081981
|
p00022
|
u136916346
|
1529203341
|
Python
|
Python3
|
py
|
Accepted
| 40
|
5636
| 198
|
while 1:
n=int(input())
if not n:break
dp=[0 for _ in range(n)]
dp[0]=int(input())
for i in range(1,n):
v=int(input())
dp[i]=max(dp[i-1]+v,v)
print(max(dp))
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,484
|
s376197132
|
p00022
|
u650035614
|
1530635653
|
Python
|
Python3
|
py
|
Accepted
| 40
|
5712
| 337
|
def max_sub(array):
x = max(array[0], 0)
ans = 0
for a in array[1:]:
x = max(0, x+a)
ans = max(ans, x)
return ans
while True:
n = int(input())
if n == 0:
break
array = [int(input()) for _ in range(n)]
ans = max_sub(array)
ans = max(array) if ans <= 0 else ans
print(ans)
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,485
|
s213687571
|
p00022
|
u647766105
|
1354431537
|
Python
|
Python
|
py
|
Accepted
| 40
|
4452
| 258
|
while True:
n=input()
if n == 0: break
a=[input() for i in range(n)]
m=max(a)
if m<=0: print m
else:
ans,temp=0,0
for i in a:
temp=max(0,temp+i)
ans=max(ans,temp)
print ans
#temp
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,486
|
s858177098
|
p00022
|
u782850731
|
1362173989
|
Python
|
Python
|
py
|
Accepted
| 20
|
4420
| 795
|
from __future__ import (division, absolute_import, print_function,
unicode_literals)
from sys import stdin
from array import array
def grouping(nums):
sign = None
L = array(b'i')
for s, n in ((i < 0, i) for i in nums):
if sign is s:
L[-1] += n
else:
sign = s
L.append(n)
if len(L) and L[-1] <= 0:
del L[-1]
if len(L) and L[0] <= 0:
del L[0]
return L
while True:
n = int(stdin.readline())
if not n:
break
L = array(b'i', (int(stdin.readline()) for _ in xrange(n)))
val = max(L)
if val <= 0:
print(val)
continue
ans, temp = 0, 0
for i in grouping(L):
temp = max(0, temp+i)
ans = max(ans, temp)
print(ans)
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,487
|
s134327682
|
p00022
|
u813384600
|
1380541066
|
Python
|
Python
|
py
|
Accepted
| 20
|
4472
| 273
|
while True:
n = int(raw_input())
if n == 0:
break
a = [0] * n
dp = [0] * n
for i in range(n):
a[i] = int(raw_input())
if i == 0:
dp[0] = a[0]
else:
dp[i] = max(dp[i-1]+a[i], a[i])
print max(dp)
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,488
|
s239022934
|
p00022
|
u912237403
|
1394287602
|
Python
|
Python
|
py
|
Accepted
| 40
|
4204
| 158
|
n=input()
while n:
x=-100000
m=x
s=0
while n:
a=input()
x=max(x,0)+a
m=max(m,x)
n-=1
print m
n=input()
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,489
|
s579695492
|
p00022
|
u912237403
|
1394288311
|
Python
|
Python
|
py
|
Accepted
| 40
|
4200
| 146
|
n=input()
while n:
x=-100000
m=x
s=0
while n:
x=input()+max(0,x)
m=max(m,x)
n-=1
print m
n=input()
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,490
|
s783483968
|
p00022
|
u708217907
|
1398563755
|
Python
|
Python
|
py
|
Accepted
| 20
|
4288
| 263
|
while True:
n = int(raw_input())
if n == 0: break
max_n = max_m = -100000
r = 0
for i in range(n):
m = int(raw_input())
max_n = max(max_n, m)
r = max(r+m, 0)
max_m = max(max_m, r)
if max_n > 0:
print max_m
else:
print max_n
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,491
|
s916866619
|
p00022
|
u491763171
|
1401138260
|
Python
|
Python
|
py
|
Accepted
| 30
|
4388
| 257
|
while 1:
n = input()
if n == 0:
break
A = []
for i in xrange(n):
A.append(int(raw_input()))
dp = [0] * len(A)
dp[0] = A[0]
for i in xrange(1, len(A)):
dp[i] = max(dp[i - 1] + A[i], A[i])
print max(dp)
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,492
|
s645525929
|
p00022
|
u491763171
|
1401138327
|
Python
|
Python
|
py
|
Accepted
| 20
|
4288
| 225
|
while 1:
n = int(raw_input())
if n == 0:
break
A = [0] * n
for i in xrange(n):
A[i] = int(raw_input())
for i in xrange(1, len(A)):
A[i] = max(A[i - 1] + A[i], A[i])
print max(A)
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,493
|
s796560757
|
p00022
|
u436634575
|
1401143659
|
Python
|
Python3
|
py
|
Accepted
| 50
|
6768
| 204
|
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))
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,494
|
s910280607
|
p00022
|
u877347085
|
1591527699
|
Python
|
Python3
|
py
|
Accepted
| 40
|
5720
| 410
|
def maximumSubArray(array):
n = len(array)
dp = [0]*n # dp[i]: i番目までの全ての部分配列の中の最大の総和
dp[0] = array[0]
for i in range(1, n):
dp[i] = max(dp[i - 1] + array[i], array[i])
return max(dp)
while True:
n = int(input())
a = []
if n == 0:
break
for _ in range(n):
a.append(int(input()))
print(maximumSubArray(a))
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,495
|
s727284774
|
p00022
|
u176870835
|
1589575861
|
Python
|
Python3
|
py
|
Accepted
| 30
|
5676
| 349
|
# INF = float("inf")
import sys,bisect
sys.setrecursionlimit(15000)
st = []
ar = 0
while True:
n = int(sys.stdin.readline())
if n == 0:
break
a = [int(sys.stdin.readline()) for _ in range(n)]
ml = mg = a[0]
#print(a)
for i in range(1,n):
ml = max(ml+a[i],a[i])
mg = max(mg,ml)
#print(ml,mg,a[i])
print(mg)
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,496
|
s557076824
|
p00022
|
u260980560
|
1588731956
|
Python
|
Python3
|
py
|
Accepted
| 30
|
5612
| 352
|
import sys
readline = sys.stdin.readline
write = sys.stdout.write
def solve():
N = int(readline())
if N == 0:
return False
mi = su = 0
ans = -10**9
for i in range(N):
a = int(readline())
su += a
ans = max(ans, su - mi)
mi = min(su, mi)
print(ans)
return True
while solve():
...
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,497
|
s091337145
|
p00022
|
u630911389
|
1575642526
|
Python
|
Python3
|
py
|
Accepted
| 40
|
5636
| 1,100
|
while 1:
try:
n = int(input())
except:break
if(n == 0):break
sum = 0
arr = []
isPlus = True
maxValue = -100000
for i in range (n):
try:
arr.append(int(input()))
except:break
if arr[i] < 0:
# 合計が0以下になってしまった場合はこれ以上計算しても意味がないのでスルーする
if sum > 0:
# plusが連続して続いていた場合
if(isPlus):
# 最大値を更新
maxValue = max(maxValue,sum)
isPlus = False
sum += arr[i]
# 0未満になったら、1から計算し直す
if sum < 0 :
sum = 0
else :
sum += arr[i]
isPlus = True
if sum != 0 :
maxValue = max(maxValue,sum)
# 入力値が全てminusなので、入力値から最大のものを探す
else :
for i in arr:
maxValue = max(maxValue,i)
print(maxValue)
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,498
|
s734854953
|
p00022
|
u013648252
|
1563752952
|
Python
|
Python3
|
py
|
Accepted
| 40
|
5716
| 134
|
while 1:
n=int(input())
if n==0:break
a=[int(input())for _ in[0]*n]
for i in range(1,n):a[i]=max(a[i],a[i]+a[i-1])
print(max(a))
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,499
|
s876793346
|
p00022
|
u072053884
|
1563176196
|
Python
|
Python3
|
py
|
Accepted
| 30
|
5620
| 433
|
def solve():
from sys import stdin
f_i = stdin
while True:
n = int(f_i.readline())
if n == 0:
break
ans = int(f_i.readline())
s = ans
for i in range(n - 1):
if s > 0:
s += int(f_i.readline())
else:
s = int(f_i.readline())
if s > ans:
ans = s
print(ans)
solve()
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,500
|
s783030403
|
p00022
|
u350155409
|
1553155310
|
Python
|
Python3
|
py
|
Accepted
| 40
|
5620
| 600
|
import sys
n = int(input())
while n != 0:
max_seq = []
max_val = int(input())
for i in range(n-1):
num = int(input())
if num >= 0 and max_val >= 0:
max_val += num
else:
if max_val >= 0:
max_seq.append(max_val)
if max_val >= 0 and max_val+num >= 0:
max_val += num
elif max_val >= 0 and max_val+num < 0:
max_val = num
elif max_val < 0 and max_val < num:
max_val = num
max_seq.append(max_val)
print(max(max_seq))
n = int(input())
|
p00022
|
<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 ≤ <var>n</var> ≤ 5000 and -100000 ≤ <var>a<sub>i</sub></var> ≤ 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>
|
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
| 7,501
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.