제출 #696817

#제출 시각아이디문제언어결과실행 시간메모리
696817tsumondaiLightning Rod (NOI18_lightningrod)C++14
100 / 100
1982 ms262144 KiB
#include<bits/stdc++.h>
using namespace std;
stack<pair<int, int>> stk;
vector<pair<int, int>> temp;

int main() {
    cin.tie(0)->sync_with_stdio(false);
    //freopen("thunder.inp", "r", stdin);
    //freopen("thunder.out", "w", stdout);
    int n;
	cin >> n;
	for (int i=1; i<=n; i++) {
        int x,y;
        cin >> x >> y;
        temp.push_back({x,y});
	}
	sort(temp.begin(), temp.end());
	for (int i=0; i<n; i++) {
		int x,y;
		x=temp[i].first; y=temp[i].second;
		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});
		}
	}
	cout << stk.size();
	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...