Submission #348265

#TimeUsernameProblemLanguageResultExecution timeMemory
348265MrDominoSafety (NOI18_safety)C++14
33 / 100
2085 ms1476 KiB
#include <bits/stdc++.h> using namespace std; typedef long long ll; #define int ll multiset<int> local_minimum(multiset<int> s, int h) { assert((int) s.size() % 2 == 0); multiset<int> s2; int slope = -(int) s.size() / 2; for (auto &x : s) { if (slope < 0) { s2.insert(x - h); } if (slope >= 0) { s2.insert(x + h); } slope++; } return s2; } int get(multiset<int> s, int a, int b) { int n = (int) s.size(); vector<int> xs; for (auto &it : s) { xs.push_back(it); } for (int i = n - 1; i >= 0; i--) { b += xs[i]; a--; if (a == 0) { return b; } } assert(0); } signed main() { ios::sync_with_stdio(0); cin.tie(0); multiset<int> s; int n, h, x, b = 0; cin >> n >> h >> x; s.insert(x); s.insert(x); b = -x; for (int i = 2; i <= n; i++) { s = local_minimum(s, h); cin >> x; b -= (i - 1) * h; /// I have no clue why this happens lol s.insert(x); s.insert(x); auto it = s.end(); it--; b -= x; } cout << get(s, (int) s.size() / 2, b) << "\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...
#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...