10842 | 2024-04-16 14:20:01 | 42 | Metróutasok | pypy3 | Accepted 100/100 | 209ms | 123556 KiB |
#from sys import stdin, stdout
#input=stdin.readline
def main():
N = int(input())
A = list(map(int, input().split()))
s=sum(A)//2
maxi=mini=0
for i in range(N-1,-1,-1):
if maxi+A[i]<=s:
maxi+=A[i]
else:
break
maxipre=0
for i in range(N):
if maxipre+A[i]<=s:
maxipre+=A[i]
else:
break
if maxipre>maxi:
maxi=maxipre
def test(A,k):
if max(A[0],A[-1])>k:
return False
cur=A[0]
for i in range(1,len(A)):
if cur+A[i]<=k:
cur+=A[i]
continue
if A[i]-cur>k:
return False
if (A[i]+cur-k)%2==0:
cur=k
else:
cur=k-1
cur=A[-1]
for i in range(len(A)-2,0,-1):
if cur+A[i]<=k:
cur+=A[i]
continue
if A[i]-cur>k:
return False
if (A[i]+cur-k)%2==0:
cur=k
else:
cur=k-1
return True
lo=max(A[0],A[-1])-1
hi=min(maxi,2*10**9)
#while True:
# h=hi//100
# if test(A,h):
# if h>lo:
# hi=h
# else:
# break
while hi-lo>1:
mid=(hi+lo)//2
if test(A,mid):
hi=mid
else:
lo=mid
print(hi)
print(maxi)
main()
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 48ms | 76744 KiB | ||||
2 | Accepted | 181ms | 119812 KiB | ||||
subtask2 | 12/12 | ||||||
3 | Accepted | 46ms | 77028 KiB | ||||
4 | Accepted | 43ms | 77660 KiB | ||||
5 | Accepted | 39ms | 77808 KiB | ||||
6 | Accepted | 46ms | 77776 KiB | ||||
7 | Accepted | 48ms | 78836 KiB | ||||
8 | Accepted | 43ms | 78440 KiB | ||||
9 | Accepted | 39ms | 78924 KiB | ||||
10 | Accepted | 48ms | 78712 KiB | ||||
11 | Accepted | 43ms | 79524 KiB | ||||
12 | Accepted | 39ms | 79816 KiB | ||||
13 | Accepted | 46ms | 79112 KiB | ||||
14 | Accepted | 43ms | 79504 KiB | ||||
15 | Accepted | 39ms | 79424 KiB | ||||
16 | Accepted | 48ms | 79108 KiB | ||||
subtask3 | 12/12 | ||||||
17 | Accepted | 46ms | 77028 KiB | ||||
18 | Accepted | 43ms | 77660 KiB | ||||
19 | Accepted | 39ms | 77808 KiB | ||||
20 | Accepted | 46ms | 77776 KiB | ||||
21 | Accepted | 48ms | 78836 KiB | ||||
22 | Accepted | 43ms | 78440 KiB | ||||
23 | Accepted | 39ms | 78924 KiB | ||||
24 | Accepted | 48ms | 78712 KiB | ||||
25 | Accepted | 43ms | 79524 KiB | ||||
26 | Accepted | 39ms | 79816 KiB | ||||
27 | Accepted | 46ms | 79988 KiB | ||||
28 | Accepted | 46ms | 79820 KiB | ||||
29 | Accepted | 46ms | 79972 KiB | ||||
30 | Accepted | 46ms | 80028 KiB | ||||
31 | Accepted | 46ms | 80228 KiB | ||||
32 | Accepted | 46ms | 80880 KiB | ||||
33 | Accepted | 43ms | 80720 KiB | ||||
34 | Accepted | 46ms | 80784 KiB | ||||
35 | Accepted | 43ms | 80708 KiB | ||||
36 | Accepted | 46ms | 80856 KiB | ||||
37 | Accepted | 46ms | 79112 KiB | ||||
38 | Accepted | 43ms | 79504 KiB | ||||
39 | Accepted | 46ms | 80756 KiB | ||||
40 | Accepted | 43ms | 80436 KiB | ||||
41 | Accepted | 39ms | 81120 KiB | ||||
42 | Accepted | 46ms | 80848 KiB | ||||
43 | Accepted | 39ms | 79424 KiB | ||||
44 | Accepted | 48ms | 79108 KiB | ||||
45 | Accepted | 43ms | 80740 KiB | ||||
46 | Accepted | 39ms | 81104 KiB | ||||
47 | Accepted | 39ms | 81124 KiB | ||||
48 | Accepted | 39ms | 80704 KiB | ||||
49 | Accepted | 46ms | 80676 KiB | ||||
subtask4 | 16/16 | ||||||
50 | Accepted | 46ms | 77028 KiB | ||||
51 | Accepted | 43ms | 77660 KiB | ||||
52 | Accepted | 39ms | 77808 KiB | ||||
53 | Accepted | 46ms | 77776 KiB | ||||
54 | Accepted | 48ms | 78836 KiB | ||||
55 | Accepted | 43ms | 78440 KiB | ||||
56 | Accepted | 39ms | 78924 KiB | ||||
57 | Accepted | 48ms | 78712 KiB | ||||
58 | Accepted | 43ms | 79524 KiB | ||||
59 | Accepted | 39ms | 79816 KiB | ||||
60 | Accepted | 46ms | 79988 KiB | ||||
61 | Accepted | 46ms | 79820 KiB | ||||
62 | Accepted | 46ms | 79972 KiB | ||||
63 | Accepted | 46ms | 80028 KiB | ||||
64 | Accepted | 46ms | 80228 KiB | ||||
65 | Accepted | 46ms | 80880 KiB | ||||
66 | Accepted | 43ms | 80720 KiB | ||||
67 | Accepted | 46ms | 80784 KiB | ||||
68 | Accepted | 43ms | 80708 KiB | ||||
69 | Accepted | 46ms | 80856 KiB | ||||
70 | Accepted | 43ms | 81316 KiB | ||||
71 | Accepted | 41ms | 81440 KiB | ||||
72 | Accepted | 41ms | 81320 KiB | ||||
73 | Accepted | 41ms | 81360 KiB | ||||
74 | Accepted | 48ms | 81192 KiB | ||||
75 | Accepted | 45ms | 81476 KiB | ||||
76 | Accepted | 41ms | 81544 KiB | ||||
77 | Accepted | 41ms | 81572 KiB | ||||
78 | Accepted | 41ms | 81776 KiB | ||||
79 | Accepted | 41ms | 81736 KiB | ||||
80 | Accepted | 46ms | 79112 KiB | ||||
81 | Accepted | 43ms | 79504 KiB | ||||
82 | Accepted | 46ms | 80756 KiB | ||||
83 | Accepted | 43ms | 80436 KiB | ||||
84 | Accepted | 39ms | 81120 KiB | ||||
85 | Accepted | 46ms | 80848 KiB | ||||
86 | Accepted | 39ms | 79424 KiB | ||||
87 | Accepted | 48ms | 79108 KiB | ||||
88 | Accepted | 43ms | 80740 KiB | ||||
89 | Accepted | 39ms | 81104 KiB | ||||
90 | Accepted | 39ms | 81124 KiB | ||||
91 | Accepted | 39ms | 80704 KiB | ||||
92 | Accepted | 46ms | 80676 KiB | ||||
subtask5 | 60/60 | ||||||
93 | Accepted | 46ms | 77028 KiB | ||||
94 | Accepted | 179ms | 123384 KiB | ||||
95 | Accepted | 43ms | 77660 KiB | ||||
96 | Accepted | 39ms | 77808 KiB | ||||
97 | Accepted | 46ms | 77776 KiB | ||||
98 | Accepted | 48ms | 78836 KiB | ||||
99 | Accepted | 43ms | 78440 KiB | ||||
100 | Accepted | 39ms | 78924 KiB | ||||
101 | Accepted | 48ms | 78712 KiB | ||||
102 | Accepted | 43ms | 79524 KiB | ||||
103 | Accepted | 39ms | 79816 KiB | ||||
104 | Accepted | 46ms | 79988 KiB | ||||
105 | Accepted | 46ms | 79820 KiB | ||||
106 | Accepted | 46ms | 79972 KiB | ||||
107 | Accepted | 46ms | 80028 KiB | ||||
108 | Accepted | 46ms | 80228 KiB | ||||
109 | Accepted | 46ms | 80880 KiB | ||||
110 | Accepted | 43ms | 80720 KiB | ||||
111 | Accepted | 46ms | 80784 KiB | ||||
112 | Accepted | 43ms | 80708 KiB | ||||
113 | Accepted | 46ms | 80856 KiB | ||||
114 | Accepted | 43ms | 81316 KiB | ||||
115 | Accepted | 41ms | 81440 KiB | ||||
116 | Accepted | 41ms | 81320 KiB | ||||
117 | Accepted | 41ms | 81360 KiB | ||||
118 | Accepted | 48ms | 81192 KiB | ||||
119 | Accepted | 45ms | 81476 KiB | ||||
120 | Accepted | 41ms | 81544 KiB | ||||
121 | Accepted | 41ms | 81572 KiB | ||||
122 | Accepted | 41ms | 81776 KiB | ||||
123 | Accepted | 41ms | 81736 KiB | ||||
124 | Accepted | 207ms | 123336 KiB | ||||
125 | Accepted | 208ms | 123192 KiB | ||||
126 | Accepted | 209ms | 123520 KiB | ||||
127 | Accepted | 202ms | 123428 KiB | ||||
128 | Accepted | 206ms | 123556 KiB | ||||
129 | Accepted | 180ms | 123200 KiB | ||||
130 | Accepted | 186ms | 123520 KiB | ||||
131 | Accepted | 150ms | 123208 KiB | ||||
132 | Accepted | 207ms | 123548 KiB | ||||
133 | Accepted | 46ms | 79112 KiB | ||||
134 | Accepted | 43ms | 79504 KiB | ||||
135 | Accepted | 46ms | 80756 KiB | ||||
136 | Accepted | 43ms | 80436 KiB | ||||
137 | Accepted | 39ms | 81120 KiB | ||||
138 | Accepted | 46ms | 80848 KiB | ||||
139 | Accepted | 39ms | 79424 KiB | ||||
140 | Accepted | 48ms | 79108 KiB | ||||
141 | Accepted | 43ms | 80740 KiB | ||||
142 | Accepted | 39ms | 81104 KiB | ||||
143 | Accepted | 39ms | 81124 KiB | ||||
144 | Accepted | 120ms | 113776 KiB | ||||
145 | Accepted | 128ms | 111484 KiB | ||||
146 | Accepted | 108ms | 113376 KiB | ||||
147 | Accepted | 86ms | 103420 KiB | ||||
148 | Accepted | 145ms | 113644 KiB | ||||
149 | Accepted | 109ms | 112060 KiB | ||||
150 | Accepted | 39ms | 80704 KiB | ||||
151 | Accepted | 46ms | 80676 KiB | ||||
152 | Accepted | 104ms | 111628 KiB |