Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "bits/stdc++.h"
- using namespace std;
- int main() {
- int n;
- cin >> n;
- vector<pair<int, int>> v;
- for(int i = 0; i < n; ++i) {
- int a, b;
- cin >> a >> b;
- v.push_back({a, b});
- }
- set<int> S;
- for(auto [a, b] : v) {
- S.insert(a);
- S.insert(b);
- }
- map<int, int> mapTo;
- int nextNum = 1;
- for(int num : S)
- mapTo[num] = nextNum++;
- for(int i = 0; i < n; ++i) {
- v[i].first = mapTo[ v[i].first ];
- v[i].second = mapTo[ v[i].second ];
- }
- // ------- solução em baixo
- vector<int> cnt(500000);
- for(int i = 0; i < n; ++i) {
- cnt[ v[i].first ]++;
- cnt[ v[i].second + 1 ]--;
- }
- int ans = 0;
- for(int i = 1; i < cnt.size(); ++i) {
- cnt[i] += cnt[i - 1];
- ans = max(ans, cnt[i]);
- }
- cout << ans << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement