Submission #668418

#TimeUsernameProblemLanguageResultExecution timeMemory
668418600MihneaSafety (NOI18_safety)C++17
66 / 100
2083 ms716 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()); if (x <= a.back()) { sol += a.back() - x; b.push_back(a.back()); a.pop_back(); a.push_back(x); a.push_back(x); } else { if (x >= b[0]) { if (1) { sol += 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); } } assert((int) a.size() == i + 1); assert((int) b.size() == i + 1); sort(a.begin(), a.end()); sort(b.begin(), b.end()); continue; cout << " ---> "; for (auto &it : a) { cout << it << " "; } cout << " and "; for (auto &it : b) { cout << it << " "; } cout << "\n"; } 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...