107722024-04-11 18:41:06mraronMetróutasokcpp17Accepted 100/10056ms6316 KiB
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<cassert>
#include<unordered_map>
#include<unordered_set>
#include<functional>
#include<queue>
#include<stack>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<numeric>
#include<random>
#include<chrono>
#include<bitset>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
//using namespace __gnu_pbds;

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define sz(x) (int)(x).size()
#define gc getchar
#define IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define mp make_pair
#define ins insert
#define chkmn(x,y) (x)=min((x), (y))
#define chkmx(x,y) (x)=max((x), (y))

#ifndef ONLINE_JUDGE
#  define LOG(x) (cerr << #x << " = " << (x) << endl)
#else
#  define LOG(x) ((void)0)
#endif

using ll = long long;
using ull = unsigned long long ;
using ld = long double ;
using str = string;
//using ordered_set=tree<pair<int,int>, null_type, less<pair<int,int>>, rb_tree_tag, tree_order_statistics_node_update>;

const double PI=acos(-1);
const ll INF = 1LL<<62;
const ll MINF = -(1LL<<62);

template<typename T> T getint() {
    T val=0;
    char c;
    
    bool neg=false;
    while((c=gc()) && !(c>='0' && c<='9')) {
        neg|=c=='-';
    }

    do {
        val=(val*10)+c-'0';
    } while((c=gc()) && (c>='0' && c<='9'));

    return val*(neg?-1:1);
}

//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); uniform_int_distribution<int>(0, n-1)(rng)


int main() {
    IO;
    int n;
    cin>>n;
    vector<ll> a(n);
    for(int i=0;i<n;++i) cin>>a[i];
    ll sum=accumulate(all(a), 0LL)/2;
    ll mn=1LL<<60, mx=0, curr=0;
    for(int i=0;i<n;++i) {
        ll can_up=min(a[i], sum);
        ll can_down=min(curr, a[i]-can_up);
        curr+=can_up-can_down;
        chkmx(mx, curr);
        sum-=can_up;
    }

    auto test=[&](ll currMn) -> bool {
        bool ok=true;
        ll sum=accumulate(all(a), 0LL)/2;
        ll curr=0;
        for(int j=0;j<n && ok;++j) {
            ll can_up=min({a[j], sum, (currMn+a[j]-curr)/2});
            ll can_down=min(curr, a[j]-can_up);
            ok&=can_up+can_down==a[j] && can_up>=0 && can_down>=0;
            if(j==0) ok&=can_down==0;
            if(j==n-1) ok&=can_up==0;
            curr+=can_up-can_down;
            sum-=can_up;
        }
        return ok;
    };

    for(ll i=60;i>=0;i--) {
        ll currMn = mn - (1LL<<i);
        if(currMn>0 && test(currMn)) {
            mn=currMn;
        }
    }

    cout<<mn<<"\n";
    cout<<mx<<"\n";
    
    return 0;
}
SubtaskSumTestVerdictTimeMemory
subtask10/0
1Accepted3ms1832 KiB
2Accepted54ms3516 KiB
subtask212/12
3Accepted3ms2540 KiB
4Accepted3ms2496 KiB
5Accepted3ms2816 KiB
6Accepted3ms2672 KiB
7Accepted3ms2812 KiB
8Accepted3ms2900 KiB
9Accepted3ms3128 KiB
10Accepted3ms3196 KiB
11Accepted3ms3220 KiB
12Accepted3ms3288 KiB
13Accepted3ms3396 KiB
14Accepted3ms3400 KiB
15Accepted2ms3272 KiB
16Accepted3ms3376 KiB
subtask312/12
17Accepted3ms2540 KiB
18Accepted3ms2496 KiB
19Accepted3ms2816 KiB
20Accepted3ms2672 KiB
21Accepted3ms2812 KiB
22Accepted3ms2900 KiB
23Accepted3ms3128 KiB
24Accepted3ms3196 KiB
25Accepted3ms3220 KiB
26Accepted3ms3288 KiB
27Accepted3ms3616 KiB
28Accepted3ms3488 KiB
29Accepted3ms3716 KiB
30Accepted3ms3716 KiB
31Accepted3ms3704 KiB
32Accepted2ms3700 KiB
33Accepted3ms3828 KiB
34Accepted3ms4188 KiB
35Accepted3ms4188 KiB
36Accepted3ms4272 KiB
37Accepted3ms3396 KiB
38Accepted3ms3400 KiB
39Accepted3ms4272 KiB
40Accepted3ms4272 KiB
41Accepted3ms4368 KiB
42Accepted3ms4372 KiB
43Accepted2ms3272 KiB
44Accepted3ms3376 KiB
45Accepted3ms4272 KiB
46Accepted3ms4272 KiB
47Accepted3ms4364 KiB
48Accepted3ms4368 KiB
49Accepted3ms4368 KiB
subtask416/16
50Accepted3ms2540 KiB
51Accepted3ms2496 KiB
52Accepted3ms2816 KiB
53Accepted3ms2672 KiB
54Accepted3ms2812 KiB
55Accepted3ms2900 KiB
56Accepted3ms3128 KiB
57Accepted3ms3196 KiB
58Accepted3ms3220 KiB
59Accepted3ms3288 KiB
60Accepted3ms3616 KiB
61Accepted3ms3488 KiB
62Accepted3ms3716 KiB
63Accepted3ms3716 KiB
64Accepted3ms3704 KiB
65Accepted2ms3700 KiB
66Accepted3ms3828 KiB
67Accepted3ms4188 KiB
68Accepted3ms4188 KiB
69Accepted3ms4272 KiB
70Accepted3ms4400 KiB
71Accepted3ms4484 KiB
72Accepted3ms4552 KiB
73Accepted3ms4548 KiB
74Accepted3ms4676 KiB
75Accepted3ms4772 KiB
76Accepted3ms4920 KiB
77Accepted3ms4760 KiB
78Accepted3ms4760 KiB
79Accepted3ms5008 KiB
80Accepted3ms3396 KiB
81Accepted3ms3400 KiB
82Accepted3ms4272 KiB
83Accepted3ms4272 KiB
84Accepted3ms4368 KiB
85Accepted3ms4372 KiB
86Accepted2ms3272 KiB
87Accepted3ms3376 KiB
88Accepted3ms4272 KiB
89Accepted3ms4272 KiB
90Accepted3ms4364 KiB
91Accepted3ms4368 KiB
92Accepted3ms4368 KiB
subtask560/60
93Accepted3ms2540 KiB
94Accepted54ms6228 KiB
95Accepted3ms2496 KiB
96Accepted3ms2816 KiB
97Accepted3ms2672 KiB
98Accepted3ms2812 KiB
99Accepted3ms2900 KiB
100Accepted3ms3128 KiB
101Accepted3ms3196 KiB
102Accepted3ms3220 KiB
103Accepted3ms3288 KiB
104Accepted3ms3616 KiB
105Accepted3ms3488 KiB
106Accepted3ms3716 KiB
107Accepted3ms3716 KiB
108Accepted3ms3704 KiB
109Accepted2ms3700 KiB
110Accepted3ms3828 KiB
111Accepted3ms4188 KiB
112Accepted3ms4188 KiB
113Accepted3ms4272 KiB
114Accepted3ms4400 KiB
115Accepted3ms4484 KiB
116Accepted3ms4552 KiB
117Accepted3ms4548 KiB
118Accepted3ms4676 KiB
119Accepted3ms4772 KiB
120Accepted3ms4920 KiB
121Accepted3ms4760 KiB
122Accepted3ms4760 KiB
123Accepted3ms5008 KiB
124Accepted43ms6100 KiB
125Accepted48ms6096 KiB
126Accepted45ms6172 KiB
127Accepted54ms6160 KiB
128Accepted46ms6096 KiB
129Accepted56ms6164 KiB
130Accepted56ms6164 KiB
131Accepted46ms6164 KiB
132Accepted56ms6096 KiB
133Accepted3ms3396 KiB
134Accepted3ms3400 KiB
135Accepted3ms4272 KiB
136Accepted3ms4272 KiB
137Accepted3ms4368 KiB
138Accepted3ms4372 KiB
139Accepted2ms3272 KiB
140Accepted3ms3376 KiB
141Accepted3ms4272 KiB
142Accepted3ms4272 KiB
143Accepted3ms4364 KiB
144Accepted43ms6100 KiB
145Accepted41ms5968 KiB
146Accepted48ms6228 KiB
147Accepted30ms5668 KiB
148Accepted43ms6168 KiB
149Accepted45ms6316 KiB
150Accepted3ms4368 KiB
151Accepted3ms4368 KiB
152Accepted41ms6172 KiB