0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-12-25 06:51:58 +00:00

#421. 几何问题一

https://sjzezoj.com/submission/12026
This commit is contained in:
Baoshuo Ren 2021-06-30 10:52:21 +08:00 committed by Baoshuo Ren
parent 996fcb26c4
commit af869f3887
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

46
S2OJ/421/421.cpp Normal file
View File

@ -0,0 +1,46 @@
#include <bits/stdc++.h>
using namespace std;
long long n, m, k, a[100005], sum[100005], ans;
long long getSum(long long l, long long r) {
long long len = r - l + 1;
if (len % 2 == 0) {
long long mid = l + (len / 2) - 1;
return sum[r] - sum[mid] - (sum[mid] - sum[l - 1]);
} else {
long long mid = l + r >> 1;
return sum[r] - sum[mid] - (sum[mid - 1] - sum[l - 1]);
}
return -1;
}
bool check(long long x) {
for (long long i = 1; i + x - 1 <= n; i++) {
if (getSum(i, i + x - 1) <= k) {
return true;
}
}
return false;
}
int main() {
cin >> n >> m >> k;
for (long long i = 1; i <= n; i++) {
cin >> a[i];
sum[i] = sum[i - 1] + a[i];
}
long long l = 1, r = n;
while (l <= r) {
long long mid = l + r >> 1;
if (check(mid)) {
ans = mid;
l = mid + 1;
} else {
r = mid - 1;
}
}
cout << ans << endl;
return 0;
}