mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-23 20:08:47 +00:00
parent
e4ee2b6c8e
commit
173c882d8e
47
Luogu/P3594/P3594.cpp
Normal file
47
Luogu/P3594/P3594.cpp
Normal file
@ -0,0 +1,47 @@
|
||||
#include <iostream>
|
||||
#include <deque>
|
||||
|
||||
using std::cin;
|
||||
using std::cout;
|
||||
const char endl = '\n';
|
||||
|
||||
const int N = 2e6 + 5;
|
||||
|
||||
int n, d, a[N], ans;
|
||||
long long p, sum, s[N], t[N];
|
||||
std::deque<int> q;
|
||||
|
||||
int main() {
|
||||
std::ios::sync_with_stdio(false);
|
||||
cin.tie(nullptr);
|
||||
|
||||
cin >> n >> p >> d;
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
cin >> a[i];
|
||||
|
||||
s[i] = s[i - 1] + a[i];
|
||||
}
|
||||
|
||||
for (int i = 1; i <= n; i++) {
|
||||
t[i] = s[i] - s[i - d];
|
||||
}
|
||||
|
||||
ans = d;
|
||||
sum = s[d + 1];
|
||||
q.push_back(d);
|
||||
|
||||
for (int i = d + 1, l = 1, r = 0; i <= n; sum += a[++i]) {
|
||||
while (!q.empty() && t[q.back()] <= t[i]) q.pop_back();
|
||||
q.push_back(i);
|
||||
while (sum - t[q.front()] > p) {
|
||||
if (q.front() < l + d) q.pop_front();
|
||||
sum -= a[l++];
|
||||
}
|
||||
ans = std::max(ans, i - l + 1);
|
||||
}
|
||||
|
||||
cout << ans << endl;
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Reference in New Issue
Block a user