-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathi_subway_ks.cpp
More file actions
88 lines (80 loc) · 1.81 KB
/
Copy pathi_subway_ks.cpp
File metadata and controls
88 lines (80 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/* cin : 0.55s
* scanf : 0.47s
* OK */
#include <cassert>
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <iomanip>
#include <vector>
#include <set>
#include <map>
#include <cassert>
#include <queue>
using namespace std;
#define FOR(a, b) for (int a = 0; a < (b); ++a)
#define clr(a) memset(a, 0, sizeof(a))
#define pb(i) push_back(i)
#define forab(i, a, b) for(int i = int(a); i < int(b); ++i)
#define forba(i, b, a) for(int i = int(b) - 1; i >= int(a); --i)
#define forn(i, n) forab(i, 0, n)
#ifdef LOCAL
#define debug(a) cerr << #a << ": " << a << '\n';
#else
#define debug(a)
#endif
typedef long long ll;
typedef long double ldb;
const ll INF = 1e18;
const ll MAXS = 1e15;
const int MAXC = 1e9;
const ldb EPS = 1e-8;
const ldb PI = acos(-1.0);
const int MAXN = 1e6;
ll a[MAXN + 100];
ll pr[MAXN + 100];
ll msuf[MAXN + 100];
int main() {
freopen("subway.in", "r", stdin);
freopen("subway.out", "w", stdout);
//cin.sync_with_stdio(false);
int n;
ll s;
scanf("%d%lld", &n, &s);
//cin >> n >> s;
assert(1 <= n && n <= MAXN);
assert(-MAXS <= s && s <= MAXS);
forn(i, n) {
scanf("%lld", &a[i]);
//cin >> a[i];
assert(-MAXC <= a[i] && a[i] <= MAXC);
}
pr[0] = 0;
forn(i, n)
pr[i + 1] = pr[i] + a[i];
msuf[0] = -INF;
forn(i, n + 1) {
msuf[i + 1] = max(msuf[i], pr[n - i]);
}
int ans = 0;
forn(i, n) {
int l = 0;
int r = n - i + 1;
while (l < r - 1) {
int m = (l + r) / 2;
if (msuf[n - i - m + 1] - pr[i] >= s) {
l = m;
} else {
r = m;
}
}
ans = max(ans, l);
}
cout << ans << '\n';
return 0;
}