Submission #31572

#TimeUsernameProblemLanguageResultExecution timeMemory
31572user202729Hacker (BOI15_hac)C++14
100 / 100
173 ms11948 KiB
// https://oj.uz/problem/view/BOI15_hac #include <iostream> #include <vector> #include <deque> typedef std::pair<int,int> ii; int main() { int n; std::cin >> n; std::vector<int> value (n), segvalue (n); for (int& i : value) std::cin >> i; value.insert(value.end(), value.begin(), value.end()); // for (int& i : value) std::cout << i << ' '; for (int i = 1; i < 2 * n; ++i) value[i] += value[i-1]; // conv to sum table int seglen = (n+1)/2; for (int i = 0; i < n; ++i) segvalue[i] = value[i+seglen] - value[i]; value.clear(); // no longer need value segvalue.insert(segvalue.end(), segvalue.begin(), segvalue.end()); std::deque<ii> candidatepairs; // need to calculate min of windows, then pick the max of min's // ii : index -> value (in segvalue) for (int i = 0; i < seglen-1; ++i) { while ((!candidatepairs.empty()) && candidatepairs.back().second >= segvalue[i]) candidatepairs.pop_back(); candidatepairs.emplace_back(i, segvalue[i]); } int result = -1; // need to get max for (int i = 0; i < n; ++i) { // segment [i .. i+seglen) // insert i+seglen-1 int j = i+seglen-1; while ((!candidatepairs.empty()) && candidatepairs.back().second >= segvalue[j]) candidatepairs.pop_back(); candidatepairs.emplace_back(j, segvalue[j]); // delete anything < i while ((!candidatepairs.empty()) && candidatepairs.front().first < i) candidatepairs.pop_front(); // and get the min result = std::max(result, candidatepairs.front().second); } std::cout << result << '\n'; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...