Submission #232126

#TimeUsernameProblemLanguageResultExecution timeMemory
232126KubalionzzaleSafety (NOI18_safety)C++14
100 / 100
159 ms3696 KiB
#include <iostream> #include <queue> #include <algorithm> #include <vector> using ll = long long int; ll h; int main() { std::priority_queue<ll> leftprioq; std::priority_queue<ll, std::vector<ll>, std::greater<ll> > rightprioq; ll n, x, ans = 0; std::cin >> n >> h; std::cin >> x; leftprioq.push(x); rightprioq.push(x); for (int i = 1; i < n; ++i) { std::cin >> x; ll leftnodepos = leftprioq.top() - h*i; ll rightnodepos = rightprioq.top() + h*i; // std::cout << "i: " << i << "\n"; // std::cout << "borders: " << leftelem.curtimepos(i) << " " << rightelem.curtimepos(i) << "\n"; if (x < leftnodepos) { leftprioq.pop(); leftprioq.push(x + h * i); leftprioq.push(x + h * i); ans += leftnodepos - x; // std::cout << "left: " << nextleftpos << " " << leftnodepos << "\n"; rightprioq.push(leftnodepos - h * i); } else if (x > rightnodepos) { rightprioq.pop(); rightprioq.push(x - h*i); rightprioq.push(x - h*i); ans += x - rightnodepos; // std::cout << "right: " << rightnodepos << " " << nextrightpos << "\n"; leftprioq.push(rightnodepos + h * i); } else { leftprioq.push(x + h *i); rightprioq.push(x-h*i); } } std::cout << ans; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...