# |
Submission time |
Handle |
Problem |
Language |
Result |
Execution time |
Memory |
482706 |
2021-10-26T05:56:36 Z |
mihai145 |
Safety (NOI18_safety) |
C++14 |
|
65 ms |
12600 KB |
//
// Created by Mihai145 on 10/25/2021.
//
#include <iostream>
#include <set>
using namespace std;
int N, H, x;
long long ans;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cin >> N >> H >> x;
multiset<long long> lefts, rights;
lefts.insert(x), rights.insert(x);
for(int i = 1; i < N; i++) {
cin >> x;
long long shift = 1LL * i * H;
long long lfb = *lefts.rbegin();
long long lfb_val = lfb - shift;
long long rb = *rights.begin();
long long rb_val = rb + shift;
if(x <= lfb_val) {
ans += (lfb_val - x);
lefts.insert(x + shift);
lefts.insert(x + shift);
lefts.erase(lefts.find(lfb));
rights.insert(rb);
} else if(x >= rb_val) {
ans += (x - rb_val);
rights.insert(x - shift);
rights.insert(x - shift);
rights.erase(rights.find(rb));
lefts.insert(lfb);
} else {
lefts.insert(lfb);
rights.insert(rb);
}
}
cout << ans << '\n';
return 0;
}
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Incorrect |
65 ms |
12600 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |
# |
Verdict |
Execution time |
Memory |
Grader output |
1 |
Correct |
0 ms |
204 KB |
Output is correct |
2 |
Correct |
0 ms |
204 KB |
Output is correct |
3 |
Incorrect |
0 ms |
204 KB |
Output isn't correct |
4 |
Halted |
0 ms |
0 KB |
- |