Skip to content

Commit

Permalink
Add 01863.cpp
Browse files Browse the repository at this point in the history
  • Loading branch information
Hiyabye committed Apr 1, 2024
1 parent bc32ce9 commit 01c7f83
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions 01xxx/01863.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#include <algorithm>
#include <iostream>
#include <stack>
#include <vector>
using namespace std;

void solve(void) {
int n; cin >> n;
vector<pair<int, int>> v(n);
for (int i=0; i<n; i++) cin >> v[i].first >> v[i].second;
sort(v.begin(), v.end());

int ans = 0;
stack<int> s;
s.push(0);
for (int i=0; i<n; i++) {
if (s.top() < v[i].second) ans++, s.push(v[i].second);
else {
while (!s.empty() && s.top() > v[i].second) s.pop();
if (s.top() < v[i].second) ans++, s.push(v[i].second);
}
}
cout << ans;
}

int main(void) {
ios::sync_with_stdio(false);
cin.tie(nullptr);

solve();
return 0;
}

0 comments on commit 01c7f83

Please sign in to comment.