Submission #265313

#TimeUsernameProblemLanguageResultExecution timeMemory
265313T0p_Lightning Rod (NOI18_lightningrod)C++14
66 / 100
2080 ms163824 KiB
#include<bits/stdc++.h>
using namespace std;

stack<pair<int, int>> stk;

int main()
{
	int n;
	scanf(" %d",&n);
	while(n--)
	{
		int x, y;
		scanf(" %d %d",&x,&y);
		if(stk.empty()) stk.push({x, y});
		else
		{
			int h = stk.top().second - x + stk.top().first;
			if(h >= y) continue ;
			while(!stk.empty())
			{
				int h = y - x + stk.top().first;
				if(h >= stk.top().second) stk.pop();
				else break ;
			}
			stk.push({x, y});
		}
	}
	printf("%d\n",stk.size());
	return 0;
}

Compilation message (stderr)

lightningrod.cpp: In function 'int main()':
lightningrod.cpp:28: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=]
   28 |  printf("%d\n",stk.size());
      |          ~^    ~~~~~~~~~~
      |           |            |
      |           int          std::stack<std::pair<int, int> >::size_type {aka long unsigned int}
      |          %ld
lightningrod.cpp:9:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
    9 |  scanf(" %d",&n);
      |  ~~~~~^~~~~~~~~~
lightningrod.cpp:13:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   13 |   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...