Submission #991950

# Submission time Handle Problem Language Result Execution time Memory
991950 2024-06-03T12:49:39 Z inventiontime Safety (NOI18_safety) C++17
0 / 100
48 ms 5696 KB
#include <bits/stdc++.h>
using namespace std;

#define int ll
#define fast_io ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define loop(i, n) for(int i = 0; i < n; i++)
#define loop1(i, n) for(int i = 1; i <= n; i++)
#define all(x) (x).begin(), (x).end()
#define all1(x) (x).begin() + 1, (x).end()
#define pb push_back
#define ff first
#define ss second

typedef long long ll;
typedef array<int, 2> ii;
typedef array<int, 3> ti;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ii> vii;
typedef vector<ti> vti;

void solve() {

	int n, h;
	cin >> n >> h;

	vi s(n+1);
	loop1(i, n) cin >> s[i];

	priority_queue<int, vi, less<int>> left;
	priority_queue<int, vi, greater<int>> right;
	int lof = 0;
	int rof = 0;
	int base = 0;

	left.push(s[1]);
	right.push(s[1]);

	loop1(i, n) if(i != 1) {

		lof -= h;
		rof += h;

		int l = left.top() + lof;
		int r = right.top() + rof;
		
		if(l <= s[i] and s[i] <= r) {
			left.push(s[i] - lof);
			right.push(s[i] - rof);
		} else if(s[i] < l) {
			left.push(s[i] - lof);
			left.push(s[i] - lof);
			int p = left.top() + lof; left.pop();
			right.push(p - rof);
			p = p - (left.top() + lof);
			base += p;
		} else {
			right.push(s[i] - rof);
			right.push(s[i] - rof);
			int p = right.top() + rof; right.pop();
			left.push(p - lof);
			p = (right.top() + rof) - p;
			base += p;
		}

	}

	cout << base << endl;

}

signed main() {
	
	int t = 1; //cin >> t;
	while(t--) solve();
	return 0;

}
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 348 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 0 ms 344 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Incorrect 48 ms 5696 KB Output isn't correct
2 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -
# Verdict Execution time Memory Grader output
1 Correct 0 ms 348 KB Output is correct
2 Correct 0 ms 348 KB Output is correct
3 Incorrect 0 ms 348 KB Output isn't correct
4 Halted 0 ms 0 KB -