Submission #668419

#TimeUsernameProblemLanguageResultExecution timeMemory
668419600MihneaSafety (NOI18_safety)C++17
0 / 100
2078 ms644 KiB
#include <bits/stdc++.h> using namespace std; #define int long long signed main() { #ifdef ONPC freopen ("input.txt", "r", stdin); #endif // ONPC #ifndef ONPC ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); #endif // ONPC int n, dmax, sol = 0; cin >> n >> dmax; vector<int> a, b; for (int i = 0; i < n; i++) { int x; cin >> x; if (i == 0) { a.push_back(x); b.push_back(x); continue; } for (auto &it : a) { it -= dmax; } for (auto &it : b) { it += dmax; } sort(a.begin(), a.end()); sort(b.begin(), b.end()); sol += abs(a.back() - x); if (x <= a.back()) { b.push_back(a.back()); a.pop_back(); a.push_back(x); a.push_back(x); } else { if (x >= b[0]) { a.push_back(b[0]); reverse(b.begin(), b.end()); b.pop_back(); b.push_back(x); b.push_back(x); } else { a.push_back(x); b.push_back(x); } } } cout << sol << "\n"; 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...
#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...