#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
const int N = 5e5 + 7;
vector < pair < int, pair < int, int > > > sumemici;
int v[N], s[N];
int main()
{
int n;
cin >> n;
for (int i = 1; i <= n; ++i)
cin >> v[i];
for (int i = 1; i <= n; ++i)
s[i] = s[i - 1] + v[i];
for (int i = 1; i < (n + 1) / 2; ++i)
sumemici.push_back({s[n] - s[(n + 1) / 2 + i] + s[i],{n / 2 + i + 1, i}});
for (int i = (n + 1) / 2; i <= n; ++i)
sumemici.push_back({s[i] - s[i - (n + 1) / 2], {i - n / 2 + 1, i}});
sort(sumemici.begin(), sumemici.end());
int st(1), dr(n);
for (auto i : sumemici) {
// cout << st << ' ' << dr << ' ' << i.first << ' ' << i.second.first << ' ' << i.second.second << '\n';
auto x = i.second;
if (x.second < x.first) {
if (st <= dr) {
if (st > x.second && dr < x.first)
return cout << i.first, 0;
if (st <= x.second && dr >= x.first) {
st = x.first;
dr = x.second;
///asta se poate intampla doar la inceput
}
else {
if (x.second <= st)
st = x.first;
else
dr = x.second;
}
}
else {///ambele au pe 1 si n deci nu se poate ca sa nu aiba intersectie(sa aiba int. vida)
st = max(st, x.first);
dr = min(dr, x.second);
}
}
else {
if (st <= dr) {
if (st > x.second || dr < x.first)
return cout << i.first, 0;
st = max(st, x.first);
dr = min(dr, x.second);
}
else {
if (x.first > dr && x.second < st)
return cout << i.first, 0;
if (dr <= x.first)
dr = x.second;
else
st = x.first;
}
}
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
256 KB |
Output is correct |
2 |
Correct |
2 ms |
384 KB |
Output is correct |
3 |
Correct |
4 ms |
512 KB |
Output is correct |
4 |
Correct |
48 ms |
2800 KB |
Output is correct |
5 |
Correct |
70 ms |
5868 KB |
Output is correct |
6 |
Correct |
87 ms |
6636 KB |
Output is correct |
7 |
Correct |
139 ms |
10396 KB |
Output is correct |
8 |
Correct |
181 ms |
12652 KB |
Output is correct |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
3 ms |
384 KB |
Output is correct |
2 |
Correct |
1 ms |
256 KB |
Output is correct |
3 |
Incorrect |
3 ms |
384 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |