Created
July 14, 2020 21:26
-
-
Save keddad/3cd88f3c40f8a3d03aada0b2761b1ac0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <vector> | |
#include <algorithm> | |
#include <map> | |
using namespace std; | |
struct Record | |
{ | |
int id; | |
int loc; | |
int delta; | |
}; | |
int main() | |
{ | |
int n; | |
cin >> n; | |
vector<Record> v; | |
for (int i = 0; i < n; i++) | |
{ | |
int from, to; | |
cin >> from >> to; | |
v.push_back({i, from, 1}); | |
v.push_back({i, to, -1}); | |
} | |
sort(v.begin(), v.end(), [](const Record &a, const Record &b) { | |
return a.loc > b.loc; | |
}); | |
reverse(v.begin(), v.end()); | |
vector<int> ans; | |
while (!v.empty()) | |
{ | |
int max_points = 0, current_points = 0, biggest_loc = 0; | |
for (int i = 0; i < v.size(); i++) | |
{ | |
current_points += v[i].delta; | |
if (current_points >= max_points) | |
{ | |
biggest_loc = v[i].loc; | |
max_points = current_points; | |
} | |
} | |
map<int, int> met; | |
for (int i = 0; i < v.size() && v[i].loc <= biggest_loc; i++) | |
{ | |
met[v[i].id] += v[i].delta; | |
} | |
ans.push_back(biggest_loc); | |
v.erase(remove_if(v.begin(), v.end(), [&](const Record &obj) { return met[obj.id] > 0; }), v.end()); | |
} | |
cout << ans.size() << "\n"; | |
for (auto o : ans) | |
{ | |
cout << o << " "; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment