# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
772327 |
2023-07-04T03:29:35 Z |
SLin25 |
Hacker (BOI15_hac) |
C++14 |
|
38 ms |
8272 KB |
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
typedef long long ll;
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
int n; cin >> n;
int arr[n];
int pref[n+1]{};
int k = (n + 1) / 2;
for (int i = 0; i < n; i++) {
cin >> arr[i];
}
for (int i = 1; i <= n; i++) {
pref[i] += pref[i-1] + arr[i-1];
}
int val[n]; //segment ending at index
for (int i = 0; i < n; i++) {
int prev = i - k + 1;
int tmp = 0;
if (prev < 0) {
tmp = pref[i+1] + pref[n] - pref[n + prev];
} else {
tmp = pref[i+1] - pref[prev];
}
val[i] = tmp;
}
deque<pair<int, int>> q;
int ans = 0;
for (int i = 0; i < k; i++) {
while (!q.empty() && q.back().first > val[i]) {
q.pop_back();
}
q.push_back({val[i], i});
}
ans = max(ans, q.front().first);
for (int i = k; i < n; i++) {
while (!q.empty() && q.back().first > val[i]) {
q.pop_back();
}
q.push_back({val[i], i});
if (q.front().second == i - k) q.pop_front();
ans = max(ans, q.front().first);
}
cout << ans << '\n';
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
324 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
324 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Correct |
1 ms |
212 KB |
Output is correct |
3 |
Correct |
1 ms |
340 KB |
Output is correct |
4 |
Correct |
7 ms |
1564 KB |
Output is correct |
5 |
Correct |
15 ms |
3412 KB |
Output is correct |
6 |
Correct |
20 ms |
4312 KB |
Output is correct |
7 |
Correct |
25 ms |
5196 KB |
Output is correct |
8 |
Correct |
38 ms |
8272 KB |
Output is correct |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
1 ms |
212 KB |
Output is correct |
2 |
Incorrect |
1 ms |
324 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |