Submission #104246

#TimeUsernameProblemLanguageResultExecution timeMemory
104246dupreezLightning Rod (NOI18_lightningrod)C++14
66 / 100
2053 ms79924 KiB
#include <iostream>
#include <algorithm>
#include <cstring>
#include <sstream>
#include <map>
#include <queue>
#include <vector>
#include <stack>
#define mk make_pair
#define pb push_back
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> pos;
const ll MOD = 1000000007,N=10000010;
int dp[N],n,mxv;
stack<int> st;

int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) { 
		int v1, v2;
		scanf("%d%d", &v1,&v2);
		if (i == 1) {
			mxv = v1 + v2;
			st.push(v1 - v2);
		}
		else if (mxv < v1 + v2) {
			while (!st.empty() && st.top() >= v1 - v2)st.pop();
			st.push(v1 - v2);
			mxv = v1 + v2;
		}
	}
	cout << st.size() << endl;
	return 0;
}

Compilation message (stderr)

lightningrod.cpp: In function 'int main()':
lightningrod.cpp:19:7: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
  scanf("%d", &n);
  ~~~~~^~~~~~~~~~
lightningrod.cpp:22:8: warning: ignoring return value of 'int scanf(const char*, ...)', declared with attribute warn_unused_result [-Wunused-result]
   scanf("%d%d", &v1,&v2);
   ~~~~~^~~~~~~~~~~~~~~~~
#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...