108422024-04-16 14:20:0142Metróutasokpypy3Accepted 100/100209ms123556 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()
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted48ms76744 KiB
2Accepted181ms119812 KiB
subtask212/12
3Accepted46ms77028 KiB
4Accepted43ms77660 KiB
5Accepted39ms77808 KiB
6Accepted46ms77776 KiB
7Accepted48ms78836 KiB
8Accepted43ms78440 KiB
9Accepted39ms78924 KiB
10Accepted48ms78712 KiB
11Accepted43ms79524 KiB
12Accepted39ms79816 KiB
13Accepted46ms79112 KiB
14Accepted43ms79504 KiB
15Accepted39ms79424 KiB
16Accepted48ms79108 KiB
subtask312/12
17Accepted46ms77028 KiB
18Accepted43ms77660 KiB
19Accepted39ms77808 KiB
20Accepted46ms77776 KiB
21Accepted48ms78836 KiB
22Accepted43ms78440 KiB
23Accepted39ms78924 KiB
24Accepted48ms78712 KiB
25Accepted43ms79524 KiB
26Accepted39ms79816 KiB
27Accepted46ms79988 KiB
28Accepted46ms79820 KiB
29Accepted46ms79972 KiB
30Accepted46ms80028 KiB
31Accepted46ms80228 KiB
32Accepted46ms80880 KiB
33Accepted43ms80720 KiB
34Accepted46ms80784 KiB
35Accepted43ms80708 KiB
36Accepted46ms80856 KiB
37Accepted46ms79112 KiB
38Accepted43ms79504 KiB
39Accepted46ms80756 KiB
40Accepted43ms80436 KiB
41Accepted39ms81120 KiB
42Accepted46ms80848 KiB
43Accepted39ms79424 KiB
44Accepted48ms79108 KiB
45Accepted43ms80740 KiB
46Accepted39ms81104 KiB
47Accepted39ms81124 KiB
48Accepted39ms80704 KiB
49Accepted46ms80676 KiB
subtask416/16
50Accepted46ms77028 KiB
51Accepted43ms77660 KiB
52Accepted39ms77808 KiB
53Accepted46ms77776 KiB
54Accepted48ms78836 KiB
55Accepted43ms78440 KiB
56Accepted39ms78924 KiB
57Accepted48ms78712 KiB
58Accepted43ms79524 KiB
59Accepted39ms79816 KiB
60Accepted46ms79988 KiB
61Accepted46ms79820 KiB
62Accepted46ms79972 KiB
63Accepted46ms80028 KiB
64Accepted46ms80228 KiB
65Accepted46ms80880 KiB
66Accepted43ms80720 KiB
67Accepted46ms80784 KiB
68Accepted43ms80708 KiB
69Accepted46ms80856 KiB
70Accepted43ms81316 KiB
71Accepted41ms81440 KiB
72Accepted41ms81320 KiB
73Accepted41ms81360 KiB
74Accepted48ms81192 KiB
75Accepted45ms81476 KiB
76Accepted41ms81544 KiB
77Accepted41ms81572 KiB
78Accepted41ms81776 KiB
79Accepted41ms81736 KiB
80Accepted46ms79112 KiB
81Accepted43ms79504 KiB
82Accepted46ms80756 KiB
83Accepted43ms80436 KiB
84Accepted39ms81120 KiB
85Accepted46ms80848 KiB
86Accepted39ms79424 KiB
87Accepted48ms79108 KiB
88Accepted43ms80740 KiB
89Accepted39ms81104 KiB
90Accepted39ms81124 KiB
91Accepted39ms80704 KiB
92Accepted46ms80676 KiB
subtask560/60
93Accepted46ms77028 KiB
94Accepted179ms123384 KiB
95Accepted43ms77660 KiB
96Accepted39ms77808 KiB
97Accepted46ms77776 KiB
98Accepted48ms78836 KiB
99Accepted43ms78440 KiB
100Accepted39ms78924 KiB
101Accepted48ms78712 KiB
102Accepted43ms79524 KiB
103Accepted39ms79816 KiB
104Accepted46ms79988 KiB
105Accepted46ms79820 KiB
106Accepted46ms79972 KiB
107Accepted46ms80028 KiB
108Accepted46ms80228 KiB
109Accepted46ms80880 KiB
110Accepted43ms80720 KiB
111Accepted46ms80784 KiB
112Accepted43ms80708 KiB
113Accepted46ms80856 KiB
114Accepted43ms81316 KiB
115Accepted41ms81440 KiB
116Accepted41ms81320 KiB
117Accepted41ms81360 KiB
118Accepted48ms81192 KiB
119Accepted45ms81476 KiB
120Accepted41ms81544 KiB
121Accepted41ms81572 KiB
122Accepted41ms81776 KiB
123Accepted41ms81736 KiB
124Accepted207ms123336 KiB
125Accepted208ms123192 KiB
126Accepted209ms123520 KiB
127Accepted202ms123428 KiB
128Accepted206ms123556 KiB
129Accepted180ms123200 KiB
130Accepted186ms123520 KiB
131Accepted150ms123208 KiB
132Accepted207ms123548 KiB
133Accepted46ms79112 KiB
134Accepted43ms79504 KiB
135Accepted46ms80756 KiB
136Accepted43ms80436 KiB
137Accepted39ms81120 KiB
138Accepted46ms80848 KiB
139Accepted39ms79424 KiB
140Accepted48ms79108 KiB
141Accepted43ms80740 KiB
142Accepted39ms81104 KiB
143Accepted39ms81124 KiB
144Accepted120ms113776 KiB
145Accepted128ms111484 KiB
146Accepted108ms113376 KiB
147Accepted86ms103420 KiB
148Accepted145ms113644 KiB
149Accepted109ms112060 KiB
150Accepted39ms80704 KiB
151Accepted46ms80676 KiB
152Accepted104ms111628 KiB