Submission #548750

#TimeUsernameProblemLanguageResultExecution timeMemory
548750usukhbaatarLightning Rod (NOI18_lightningrod)C++14
70 / 100
2041 ms102632 KiB
#include <stack>
#include <cstdio>

using namespace std;

stack<pair<int, int>> s;

int main() {
	int n, x, y;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &x, &y);
		int l = x - y;
		int r = x + y;
		if (!s.empty()) {
			if (s.top().first <= l && r <= s.top().second)
				continue;
		}
		while (!s.empty() && l <= s.top().first && s.top().second <= r) s.pop();
		s.push({l, r});
	}
	printf("%d\n", s.size());
}

Compilation message (stderr)

lightningrod.cpp: In function 'int main()':
lightningrod.cpp:22:11: warning: format '%d' expects argument of type 'int', but argument 2 has type 'std::stack<std::pair<int, int> >::size_type' {aka 'long unsigned int'} [-Wformat=]
   22 |  printf("%d\n", s.size());
      |          ~^     ~~~~~~~~
      |           |           |
      |           int         std::stack<std::pair<int, int> >::size_type {aka long unsigned int}
      |          %ld
lightningrod.cpp:10:7: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   10 |  scanf("%d", &n);
      |  ~~~~~^~~~~~~~~~
lightningrod.cpp:12:8: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   12 |   scanf("%d%d", &x, &y);
      |   ~~~~~^~~~~~~~~~~~~~~~
#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...