10772 | 2024-04-11 18:41:06 | mraron | Metróutasok | cpp17 | Accepted 100/100 | 56ms | 6316 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;
}
Subtask | Sum | Test | Verdict | Time | Memory | ||
---|---|---|---|---|---|---|---|
subtask1 | 0/0 | ||||||
1 | Accepted | 3ms | 1832 KiB | ||||
2 | Accepted | 54ms | 3516 KiB | ||||
subtask2 | 12/12 | ||||||
3 | Accepted | 3ms | 2540 KiB | ||||
4 | Accepted | 3ms | 2496 KiB | ||||
5 | Accepted | 3ms | 2816 KiB | ||||
6 | Accepted | 3ms | 2672 KiB | ||||
7 | Accepted | 3ms | 2812 KiB | ||||
8 | Accepted | 3ms | 2900 KiB | ||||
9 | Accepted | 3ms | 3128 KiB | ||||
10 | Accepted | 3ms | 3196 KiB | ||||
11 | Accepted | 3ms | 3220 KiB | ||||
12 | Accepted | 3ms | 3288 KiB | ||||
13 | Accepted | 3ms | 3396 KiB | ||||
14 | Accepted | 3ms | 3400 KiB | ||||
15 | Accepted | 2ms | 3272 KiB | ||||
16 | Accepted | 3ms | 3376 KiB | ||||
subtask3 | 12/12 | ||||||
17 | Accepted | 3ms | 2540 KiB | ||||
18 | Accepted | 3ms | 2496 KiB | ||||
19 | Accepted | 3ms | 2816 KiB | ||||
20 | Accepted | 3ms | 2672 KiB | ||||
21 | Accepted | 3ms | 2812 KiB | ||||
22 | Accepted | 3ms | 2900 KiB | ||||
23 | Accepted | 3ms | 3128 KiB | ||||
24 | Accepted | 3ms | 3196 KiB | ||||
25 | Accepted | 3ms | 3220 KiB | ||||
26 | Accepted | 3ms | 3288 KiB | ||||
27 | Accepted | 3ms | 3616 KiB | ||||
28 | Accepted | 3ms | 3488 KiB | ||||
29 | Accepted | 3ms | 3716 KiB | ||||
30 | Accepted | 3ms | 3716 KiB | ||||
31 | Accepted | 3ms | 3704 KiB | ||||
32 | Accepted | 2ms | 3700 KiB | ||||
33 | Accepted | 3ms | 3828 KiB | ||||
34 | Accepted | 3ms | 4188 KiB | ||||
35 | Accepted | 3ms | 4188 KiB | ||||
36 | Accepted | 3ms | 4272 KiB | ||||
37 | Accepted | 3ms | 3396 KiB | ||||
38 | Accepted | 3ms | 3400 KiB | ||||
39 | Accepted | 3ms | 4272 KiB | ||||
40 | Accepted | 3ms | 4272 KiB | ||||
41 | Accepted | 3ms | 4368 KiB | ||||
42 | Accepted | 3ms | 4372 KiB | ||||
43 | Accepted | 2ms | 3272 KiB | ||||
44 | Accepted | 3ms | 3376 KiB | ||||
45 | Accepted | 3ms | 4272 KiB | ||||
46 | Accepted | 3ms | 4272 KiB | ||||
47 | Accepted | 3ms | 4364 KiB | ||||
48 | Accepted | 3ms | 4368 KiB | ||||
49 | Accepted | 3ms | 4368 KiB | ||||
subtask4 | 16/16 | ||||||
50 | Accepted | 3ms | 2540 KiB | ||||
51 | Accepted | 3ms | 2496 KiB | ||||
52 | Accepted | 3ms | 2816 KiB | ||||
53 | Accepted | 3ms | 2672 KiB | ||||
54 | Accepted | 3ms | 2812 KiB | ||||
55 | Accepted | 3ms | 2900 KiB | ||||
56 | Accepted | 3ms | 3128 KiB | ||||
57 | Accepted | 3ms | 3196 KiB | ||||
58 | Accepted | 3ms | 3220 KiB | ||||
59 | Accepted | 3ms | 3288 KiB | ||||
60 | Accepted | 3ms | 3616 KiB | ||||
61 | Accepted | 3ms | 3488 KiB | ||||
62 | Accepted | 3ms | 3716 KiB | ||||
63 | Accepted | 3ms | 3716 KiB | ||||
64 | Accepted | 3ms | 3704 KiB | ||||
65 | Accepted | 2ms | 3700 KiB | ||||
66 | Accepted | 3ms | 3828 KiB | ||||
67 | Accepted | 3ms | 4188 KiB | ||||
68 | Accepted | 3ms | 4188 KiB | ||||
69 | Accepted | 3ms | 4272 KiB | ||||
70 | Accepted | 3ms | 4400 KiB | ||||
71 | Accepted | 3ms | 4484 KiB | ||||
72 | Accepted | 3ms | 4552 KiB | ||||
73 | Accepted | 3ms | 4548 KiB | ||||
74 | Accepted | 3ms | 4676 KiB | ||||
75 | Accepted | 3ms | 4772 KiB | ||||
76 | Accepted | 3ms | 4920 KiB | ||||
77 | Accepted | 3ms | 4760 KiB | ||||
78 | Accepted | 3ms | 4760 KiB | ||||
79 | Accepted | 3ms | 5008 KiB | ||||
80 | Accepted | 3ms | 3396 KiB | ||||
81 | Accepted | 3ms | 3400 KiB | ||||
82 | Accepted | 3ms | 4272 KiB | ||||
83 | Accepted | 3ms | 4272 KiB | ||||
84 | Accepted | 3ms | 4368 KiB | ||||
85 | Accepted | 3ms | 4372 KiB | ||||
86 | Accepted | 2ms | 3272 KiB | ||||
87 | Accepted | 3ms | 3376 KiB | ||||
88 | Accepted | 3ms | 4272 KiB | ||||
89 | Accepted | 3ms | 4272 KiB | ||||
90 | Accepted | 3ms | 4364 KiB | ||||
91 | Accepted | 3ms | 4368 KiB | ||||
92 | Accepted | 3ms | 4368 KiB | ||||
subtask5 | 60/60 | ||||||
93 | Accepted | 3ms | 2540 KiB | ||||
94 | Accepted | 54ms | 6228 KiB | ||||
95 | Accepted | 3ms | 2496 KiB | ||||
96 | Accepted | 3ms | 2816 KiB | ||||
97 | Accepted | 3ms | 2672 KiB | ||||
98 | Accepted | 3ms | 2812 KiB | ||||
99 | Accepted | 3ms | 2900 KiB | ||||
100 | Accepted | 3ms | 3128 KiB | ||||
101 | Accepted | 3ms | 3196 KiB | ||||
102 | Accepted | 3ms | 3220 KiB | ||||
103 | Accepted | 3ms | 3288 KiB | ||||
104 | Accepted | 3ms | 3616 KiB | ||||
105 | Accepted | 3ms | 3488 KiB | ||||
106 | Accepted | 3ms | 3716 KiB | ||||
107 | Accepted | 3ms | 3716 KiB | ||||
108 | Accepted | 3ms | 3704 KiB | ||||
109 | Accepted | 2ms | 3700 KiB | ||||
110 | Accepted | 3ms | 3828 KiB | ||||
111 | Accepted | 3ms | 4188 KiB | ||||
112 | Accepted | 3ms | 4188 KiB | ||||
113 | Accepted | 3ms | 4272 KiB | ||||
114 | Accepted | 3ms | 4400 KiB | ||||
115 | Accepted | 3ms | 4484 KiB | ||||
116 | Accepted | 3ms | 4552 KiB | ||||
117 | Accepted | 3ms | 4548 KiB | ||||
118 | Accepted | 3ms | 4676 KiB | ||||
119 | Accepted | 3ms | 4772 KiB | ||||
120 | Accepted | 3ms | 4920 KiB | ||||
121 | Accepted | 3ms | 4760 KiB | ||||
122 | Accepted | 3ms | 4760 KiB | ||||
123 | Accepted | 3ms | 5008 KiB | ||||
124 | Accepted | 43ms | 6100 KiB | ||||
125 | Accepted | 48ms | 6096 KiB | ||||
126 | Accepted | 45ms | 6172 KiB | ||||
127 | Accepted | 54ms | 6160 KiB | ||||
128 | Accepted | 46ms | 6096 KiB | ||||
129 | Accepted | 56ms | 6164 KiB | ||||
130 | Accepted | 56ms | 6164 KiB | ||||
131 | Accepted | 46ms | 6164 KiB | ||||
132 | Accepted | 56ms | 6096 KiB | ||||
133 | Accepted | 3ms | 3396 KiB | ||||
134 | Accepted | 3ms | 3400 KiB | ||||
135 | Accepted | 3ms | 4272 KiB | ||||
136 | Accepted | 3ms | 4272 KiB | ||||
137 | Accepted | 3ms | 4368 KiB | ||||
138 | Accepted | 3ms | 4372 KiB | ||||
139 | Accepted | 2ms | 3272 KiB | ||||
140 | Accepted | 3ms | 3376 KiB | ||||
141 | Accepted | 3ms | 4272 KiB | ||||
142 | Accepted | 3ms | 4272 KiB | ||||
143 | Accepted | 3ms | 4364 KiB | ||||
144 | Accepted | 43ms | 6100 KiB | ||||
145 | Accepted | 41ms | 5968 KiB | ||||
146 | Accepted | 48ms | 6228 KiB | ||||
147 | Accepted | 30ms | 5668 KiB | ||||
148 | Accepted | 43ms | 6168 KiB | ||||
149 | Accepted | 45ms | 6316 KiB | ||||
150 | Accepted | 3ms | 4368 KiB | ||||
151 | Accepted | 3ms | 4368 KiB | ||||
152 | Accepted | 41ms | 6172 KiB |