Submission #787428

# Submission time Handle Problem Language Result Execution time Memory
787428 2023-07-19T07:32:32 Z Sohsoh84 Roller Coaster Railroad (IOI16_railroad) C++17
Compilation error
0 ms 0 KB
#include "railroad.h"
#include <bits/stdc++.h>

typedef long long ll;

using namespace std;

#define all(x)		(x).begin(), (x).end()
#define debug(x)	cerr << #x << ": " << x << endl;
#define sep		' '

const ll MAXN = 3e6 + 10;

ll f[MAXN], n, m;
vector<ll> comp_vec;

inline int ind(ll x) {
	return lower_bound(all(comp_vec), x) - comp_vec.begin() + 1;
}

ll plan_roller_coaster(vector<int> s, vector<int> t) {
	n = s.size();
	for (int i = 0; i < n; i++)
		comp_vec.push_back(s[i]), comp_vec.push_back(t[i]);

	sort(all(comp_vec));
	m = comp_vec.size();

	multiset<int> st;

	for (int i = 0; i < n; i++)
		f[ind(s[i])]++, f[ind(t[i])]--;

	for (int i = 1; i <= m; i++) {
		for (int j = 0; j < f[i]; j++)
			st.insert(i);
	}

	ll ans = 0, mx = 0;
	for (int i = 1; i <= m; i++) {
		while (f[i] < 0) {
			if (it != st.end()) st.erase(it);
			else {
				it = prev(it);
				ll val = comp_vec[i - 1] - comp_vec[*it - 1];
				ans += val;
				mx = max(mx, val);
			}

			f[i]++;
		}
	}

	return ans;
}

Compilation message

railroad.cpp: In function 'll plan_roller_coaster(std::vector<int>, std::vector<int>)':
railroad.cpp:42:8: error: 'it' was not declared in this scope; did you mean 'i'?
   42 |    if (it != st.end()) st.erase(it);
      |        ^~
      |        i