# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
146694 | jwvg0425 | Safety (NOI18_safety) | C++17 | 80 ms | 7136 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#include <random>
#include <functional>
#include <assert.h>
#include <math.h>
#define all(x) (x).begin(), (x).end()
#define xx first
#define yy second
using namespace std;
using i64 = long long int;
using ii = pair<int, int>;
using ii64 = pair<i64, i64>;
int main()
{
i64 n, h;
scanf("%lld %lld", &n, &h);
vector<i64> s(n);
for (int i = 0; i < n; i++)
scanf("%lld", &s[i]);
priority_queue<i64> lheap;
priority_queue<i64, vector<i64>, greater<i64>> rheap;
i64 ans = 0;
i64 loff = 0, roff = 0;
lheap.push(s[0]);
rheap.push(s[0]);
for (int i = 1; i < n; i++)
{
loff -= h;
roff += h;
i64 lend = lheap.top() + loff;
i64 rend = rheap.top() + roff;
if (s[i] >= lend && s[i] <= rend)
{
lheap.push(s[i] - loff);
rheap.push(s[i] - roff);
}
else if (s[i] < lend)
{
ans += lend - s[i];
lheap.pop();
lheap.push(s[i] - loff);
lheap.push(s[i] - loff);
rheap.push(lend - roff);
}
else if (s[i] > rend)
{
ans += s[i] - rend;
rheap.pop();
lheap.push(rend - loff);
rheap.push(s[i] - roff);
rheap.push(s[i] - roff);
}
}
printf("%lld\n", ans);
return 0;
}
Compilation message (stderr)
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |