Submission #404861

# Submission time Handle Problem Language Result Execution time Memory
404861 2021-05-15T07:47:37 Z SeDunion Safety (NOI18_safety) C++17
12 / 100
2000 ms 568 KB
#include<bits/stdc++.h>
#ifndef LOCAL
#define cerr if(false)cerr
#endif // LOCAL
using namespace std;
using ll = long long;
const int N = 1e6 + 66;

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0), cout.tie(0);
	int n; ll d;
	cin >> n >> d;
	priority_queue<ll, vector<ll>, greater<ll>>R;
	priority_queue<ll>L;
	ll ans = 0;
	for (int i = 0 ; i < n ; ++ i) {
		ll x;
		cin >> x;
		{
			auto C = L;
			while (C.size()) C.pop();
			while (L.size()) {
				C.push(L.top() - d), L.pop();
			}
			L = C;
		}
		{
			auto C = R;
			while (C.size()) C.pop();
			while (R.size()) {
				C.push(R.top() + d), R.pop();
			}
			R = C;
		}
		if (i == 0) {
			L.push(x);
			R.push(x);
			continue;
		}
		if (L.top() <= x && x <= R.top()) {
			L.push(x);
			R.push(x);
		} else if (L.top() > x) {
			assert(x <= R.top());
			ans += L.top() - (x);
			R.push(L.top());
			L.push(x);
			L.push(x);
		} else { // R.top() < x
			assert(x >= L.top());
			ans += x - R.top();
			L.push(R.top());
			R.pop();
			R.push(x);
			R.push(x);
		}
	}
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 240 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 1 ms 312 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
# Verdict Execution time Memory Grader output
1 Execution timed out 2069 ms 568 KB Time limit exceeded
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 240 KB Output is correct
8 Incorrect 1 ms 312 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 240 KB Output is correct
8 Incorrect 1 ms 312 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 240 KB Output is correct
8 Incorrect 1 ms 312 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 240 KB Output is correct
8 Incorrect 1 ms 312 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 1 ms 204 KB Output is correct
2 Correct 1 ms 204 KB Output is correct
3 Correct 1 ms 204 KB Output is correct
4 Correct 1 ms 204 KB Output is correct
5 Correct 1 ms 204 KB Output is correct
6 Correct 1 ms 204 KB Output is correct
7 Correct 1 ms 240 KB Output is correct
8 Incorrect 1 ms 312 KB Output isn't correct
9 Halted 0 ms 0 KB -