File tree Expand file tree Collapse file tree 2 files changed +85
-0
lines changed Expand file tree Collapse file tree 2 files changed +85
-0
lines changed Original file line number Diff line number Diff line change 1+ /* *
2+ * @file citybike.cpp
3+ * @author Macesuted ([email protected] ) 4+ * @date 2025-11-01
5+ *
6+ * @copyright Copyright (c) 2025
7+ *
8+ */
9+
10+ #include < bits/stdc++.h>
11+ using namespace std ;
12+
13+ #ifndef LOCAL
14+ #define endl ' \n '
15+ #endif
16+
17+ bool mem1;
18+
19+ #define maxn 200005
20+
21+ int a[maxn];
22+
23+ void solve (void ) {
24+ int n, d, c;
25+ cin >> n >> d >> c;
26+ for (int i = 1 ; i <= n; i++) cin >> a[i];
27+
28+ int l = 0 , r = d + 1 ;
29+ while (l + 1 < r) {
30+ int mid = (l + r) >> 1 ;
31+
32+ auto chk = [&](int lim) -> bool {
33+ for (int i = 1 , sum = 0 ; i <= n; i++) {
34+ sum += a[i] - lim;
35+ if (sum > 0 ) sum = 0 ;
36+ if (sum < -c) return false ;
37+ }
38+
39+ return true ;
40+ };
41+
42+ (chk (mid) ? l : r) = mid;
43+ }
44+ int L = l;
45+
46+ l = -1 , r = d;
47+ while (l + 1 < r) {
48+ int mid = (l + r) >> 1 ;
49+
50+ auto chk = [&](int lim) -> bool {
51+ for (int i = 1 , sum = 0 ; i <= n; i++) {
52+ sum += lim - a[i];
53+ if (sum > 0 ) sum = 0 ;
54+ if (sum < -c) return false ;
55+ }
56+
57+ return true ;
58+ };
59+
60+ (chk (mid) ? r : l) = mid;
61+ }
62+ int R = r;
63+
64+ cout << max (0 , R - L) << endl;
65+
66+ return ;
67+ }
68+
69+ bool mem2;
70+
71+ int main () {
72+ ios::sync_with_stdio (false ), cin.tie (nullptr );
73+ #ifdef LOCAL
74+ cerr << " Memory Cost: " << abs (&mem1 - &mem2) / 1024 . / 1024 . << " MB" << endl;
75+ #endif
76+
77+ int _ = 1 ;
78+ while (_--) solve ();
79+
80+ #ifdef LOCAL
81+ cerr << " Time Cost: " << clock () * 1000 . / CLOCKS_PER_SEC << " MS" << endl;
82+ #endif
83+ return 0 ;
84+ }
Original file line number Diff line number Diff line change @@ -19,6 +19,7 @@ My accounts on these online judge platforms:
1919- (Private) HEZOJ: Macesuted
2020- (Private) HLOJ: Macesuted
2121- [ HydroOJ] ( https://hydro.ac/ ) : [ Macesuted] ( https://hydro.ac/user/2 )
22+ - [ Kattis] ( https://open.kattis.com/ ) : [ macesuted] ( https://open.kattis.com/users/macesuted )
2223- [ LibreOJ] ( https://loj.ac/ ) : [ Macesuted] ( https://loj.ac/u/Macesuted )
2324- [ Luogu] ( https://www.luogu.com.cn/ ) : [ Macesuted] ( https://www.luogu.com.cn/user/98482 )
2425- (Private) NFLSOJ: Macesuted
You can’t perform that action at this time.
0 commit comments