Submission #1279664

#TimeUsernameProblemLanguageResultExecution timeMemory
1279664cjspd_olyLightning Rod (NOI18_lightningrod)C++17
100 / 100
306 ms155520 KiB
#include <bits/stdc++.h>
using namespace std;
inline int readInt()
{
	int x = 0;
	char ch = getchar_unlocked();
	while (ch < '0' || ch > '9')
		ch = getchar_unlocked();
	while (ch >= '0' && ch <= '9')
	{
		x = (x << 3) + (x << 1) + ch - '0';
		ch = getchar_unlocked();
	}
	return x;
}

int X[10'000'000 + 5], Y[10'000'000 + 5];
stack<pair<int, int>> s;
int main()
{
	int N = readInt();
	for (int i = 0; i < N; i++)
	{
		int x = X[i] = readInt(), y = Y[i] = readInt();
		bool add = true;
		while (s.size())
		{
			auto [px, py] = s.top();
			// * check if last rod covers current building
			if (x - px <= py - y)
			{
				add = 0; // * no need to add a rod
				break;
			}
			if (x - px <= y - py) // * ccheck if last rod is useless
				s.pop();
			else
				break;
		}

		if (add)
			s.push({X[i], Y[i]});
	}

	cout << s.size();
	// write code here
	return 0;
}
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...