Submission #158508

# Submission time Handle Problem Language Result Execution time Memory
158508 2019-10-17T13:18:40 Z gs18103 Safety (NOI18_safety) C++14
3 / 100
62 ms 1656 KB
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

ll s[202020];
multiset <ll> R;
multiset <ll, greater <ll> > L;

int main() {
	ios::sync_with_stdio(false); cin.tie(0);

	int n; ll h;
	cin >> n >> h;
	for(int i = 1; i <= n; i++) {
		cin >> s[i];
	}

	ll l = s[1], r = s[1], ans = 0;
	L.insert(s[1]), R.insert(s[1]);
	for(int i = 2; i <= n; i++) {
		l -= h, r += h;
		if(s[i] < l) {
			ans += l - s[i];
			L.insert(s[i] + h * (i - 1));
			L.insert(s[i] + h * (i - 1));
			ll d = *L.begin() - *(next(L.begin()));
			r = l; l = l - d;
			R.insert((*R.begin())-r+l);
			L.erase(*L.begin());
		}
		else if(s[i] > r) {
			ans += s[i] - r;
			R.insert(s[i] - h * (i - 1));
			R.insert(s[i] - h * (i - 1));
			ll d = *(next(R.begin())) - *(R.begin());
			l = r; r = l + d; 
			L.insert((*L.begin())+r-l);
			R.erase(*R.begin());
		}
		else {
			l = r = s[i];
			L.insert(s[i] + h * (i - 1));
			R.insert(s[i] - h * (i - 1));
		}
	}
	cout << ans;
}
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 2 ms 376 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 62 ms 1656 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Incorrect 2 ms 376 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Incorrect 2 ms 376 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Incorrect 2 ms 376 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Incorrect 2 ms 376 KB Output isn't correct
9 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 2 ms 376 KB Output is correct
2 Correct 2 ms 380 KB Output is correct
3 Correct 2 ms 376 KB Output is correct
4 Correct 2 ms 376 KB Output is correct
5 Correct 2 ms 376 KB Output is correct
6 Correct 2 ms 376 KB Output is correct
7 Correct 2 ms 376 KB Output is correct
8 Incorrect 2 ms 376 KB Output isn't correct
9 Halted 0 ms 0 KB -