108042024-04-14 13:14:20AblablablaMetróutasokcpp17Accepted 100/10082ms6728 KiB
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

int n;
vector<ll> szamok;
ll ossz = 0;

bool check(ll hatar){
    ll mn = 0;
    ll mx = 0;

    for(int i = 0; i < n; i++){
        ll mas = mn;

        if(mn >= szamok[i]){
            mn -= szamok[i];
        } else if(mx < szamok[i]){
            mn = szamok[i] - mx;
        } else{
            mn = (mn + szamok[i]) % 2;
        }

        if(mx + szamok[i] <= hatar){
            mx += szamok[i];
        } else{
            ll marad = hatar - mas;
            if((mas + szamok[i] <= hatar) || (szamok[i] <= mx + hatar)){
                mx = hatar - (marad + szamok[i]) % 2;
            } else{
                return false;
            }
        }
    }

    return (mn == 0);
}

void minKer(){
    ll l = max(szamok[0], szamok[n - 1]), r = ossz;
    ll ans = 0;
    while(l <= r){
        ll k = (l + r) / 2;

        if(check(k)){
            ans = k;
            r = k - 1;
        } else{
            l = k + 1;
        }
    }

    cout << ans << "\n";
}

void maxKer(){
    ll fent = 0;
    ll fel = 0;
    ll maxi = 0;
    for(int i = 0; i < n; i++){
        ll felszall = min(szamok[i], ossz / 2 - fel);
        ll leszall = szamok[i] - felszall;

        fent += felszall - leszall;
        fel += felszall;
        maxi = max(maxi, fent);
    }

    cout << maxi << "\n";
}

int main()
{
    cin >> n;

    szamok.assign(n, 0);
    for(ll &x : szamok){
        cin >> x;
        ossz += x;
    }

    minKer();
    maxKer();
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1876 KiB
2Accepted82ms3468 KiB
subtask212/12
3Accepted3ms2204 KiB
4Accepted3ms2276 KiB
5Accepted3ms2492 KiB
6Accepted3ms2840 KiB
7Accepted3ms2788 KiB
8Accepted3ms2792 KiB
9Accepted3ms2992 KiB
10Accepted3ms3156 KiB
11Accepted3ms3244 KiB
12Accepted2ms3184 KiB
13Accepted2ms3072 KiB
14Accepted3ms3072 KiB
15Accepted3ms3320 KiB
16Accepted3ms3284 KiB
subtask312/12
17Accepted3ms2204 KiB
18Accepted3ms2276 KiB
19Accepted3ms2492 KiB
20Accepted3ms2840 KiB
21Accepted3ms2788 KiB
22Accepted3ms2792 KiB
23Accepted3ms2992 KiB
24Accepted3ms3156 KiB
25Accepted3ms3244 KiB
26Accepted2ms3184 KiB
27Accepted3ms3284 KiB
28Accepted3ms3420 KiB
29Accepted3ms3544 KiB
30Accepted3ms3640 KiB
31Accepted3ms3852 KiB
32Accepted3ms4240 KiB
33Accepted3ms4156 KiB
34Accepted3ms4284 KiB
35Accepted3ms4408 KiB
36Accepted3ms4560 KiB
37Accepted2ms3072 KiB
38Accepted3ms3072 KiB
39Accepted3ms4560 KiB
40Accepted3ms4688 KiB
41Accepted3ms4572 KiB
42Accepted3ms4692 KiB
43Accepted3ms3320 KiB
44Accepted3ms3284 KiB
45Accepted3ms4664 KiB
46Accepted3ms4664 KiB
47Accepted3ms4664 KiB
48Accepted2ms4664 KiB
49Accepted3ms4784 KiB
subtask416/16
50Accepted3ms2204 KiB
51Accepted3ms2276 KiB
52Accepted3ms2492 KiB
53Accepted3ms2840 KiB
54Accepted3ms2788 KiB
55Accepted3ms2792 KiB
56Accepted3ms2992 KiB
57Accepted3ms3156 KiB
58Accepted3ms3244 KiB
59Accepted2ms3184 KiB
60Accepted3ms3284 KiB
61Accepted3ms3420 KiB
62Accepted3ms3544 KiB
63Accepted3ms3640 KiB
64Accepted3ms3852 KiB
65Accepted3ms4240 KiB
66Accepted3ms4156 KiB
67Accepted3ms4284 KiB
68Accepted3ms4408 KiB
69Accepted3ms4560 KiB
70Accepted3ms4668 KiB
71Accepted3ms4668 KiB
72Accepted3ms4800 KiB
73Accepted3ms4812 KiB
74Accepted3ms4812 KiB
75Accepted3ms4812 KiB
76Accepted3ms4808 KiB
77Accepted3ms4804 KiB
78Accepted3ms4804 KiB
79Accepted3ms4804 KiB
80Accepted2ms3072 KiB
81Accepted3ms3072 KiB
82Accepted3ms4560 KiB
83Accepted3ms4688 KiB
84Accepted3ms4572 KiB
85Accepted3ms4692 KiB
86Accepted3ms3320 KiB
87Accepted3ms3284 KiB
88Accepted3ms4664 KiB
89Accepted3ms4664 KiB
90Accepted3ms4664 KiB
91Accepted2ms4664 KiB
92Accepted3ms4784 KiB
subtask560/60
93Accepted3ms2204 KiB
94Accepted82ms6160 KiB
95Accepted3ms2276 KiB
96Accepted3ms2492 KiB
97Accepted3ms2840 KiB
98Accepted3ms2788 KiB
99Accepted3ms2792 KiB
100Accepted3ms2992 KiB
101Accepted3ms3156 KiB
102Accepted3ms3244 KiB
103Accepted2ms3184 KiB
104Accepted3ms3284 KiB
105Accepted3ms3420 KiB
106Accepted3ms3544 KiB
107Accepted3ms3640 KiB
108Accepted3ms3852 KiB
109Accepted3ms4240 KiB
110Accepted3ms4156 KiB
111Accepted3ms4284 KiB
112Accepted3ms4408 KiB
113Accepted3ms4560 KiB
114Accepted3ms4668 KiB
115Accepted3ms4668 KiB
116Accepted3ms4800 KiB
117Accepted3ms4812 KiB
118Accepted3ms4812 KiB
119Accepted3ms4812 KiB
120Accepted3ms4808 KiB
121Accepted3ms4804 KiB
122Accepted3ms4804 KiB
123Accepted3ms4804 KiB
124Accepted65ms6288 KiB
125Accepted65ms6384 KiB
126Accepted68ms6468 KiB
127Accepted64ms6476 KiB
128Accepted67ms6460 KiB
129Accepted79ms6380 KiB
130Accepted68ms6376 KiB
131Accepted64ms6376 KiB
132Accepted81ms6528 KiB
133Accepted2ms3072 KiB
134Accepted3ms3072 KiB
135Accepted3ms4560 KiB
136Accepted3ms4688 KiB
137Accepted3ms4572 KiB
138Accepted3ms4692 KiB
139Accepted3ms3320 KiB
140Accepted3ms3284 KiB
141Accepted3ms4664 KiB
142Accepted3ms4664 KiB
143Accepted3ms4664 KiB
144Accepted35ms6488 KiB
145Accepted32ms6620 KiB
146Accepted37ms6728 KiB
147Accepted24ms5988 KiB
148Accepted35ms6452 KiB
149Accepted32ms6452 KiB
150Accepted2ms4664 KiB
151Accepted3ms4784 KiB
152Accepted32ms6600 KiB