Submission #106410

#TimeUsernameProblemLanguageResultExecution timeMemory
106410BigChungusHacker (BOI15_hac)C++14
20 / 100
210 ms10744 KiB
#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 / 2 + i] + s[i],{i + 1, n / 2 + i}}); sumemici.push_back({s[(n + 1) / 2], {(n + 1) / 2 + 1, n}}); sumemici.push_back({s[n] - s[n - (n + 1) / 2], {1, n - (n + 1) / 2}}); for (int i = (n + 1) / 2 + 1; i < n; ++i) sumemici.push_back({s[i] - s[i - (n + 1) / 2], {i + 1, i - (n + 1) / 2}}); 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 && x.first < dr) st = x.first; else if (x.first > dr && x.second < dr) 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; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...