Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <utility>
- #include <set>
- #include <algorithm>
- using namespace std;
- bool comp(pair <int, pair<int, int>> a, pair <int, pair<int, int>> b) {
- if (a.second.second > b.second.second)
- return true;
- else if (a.second.second < b.second.second)
- return false;
- else {
- if (a.second.first < b.second.first)
- return true;
- return false;
- }
- }
- int main() {
- int n;
- cin >> n;
- vector <pair < int, pair<int, int>>> v(n);
- for (int i = 0; i < n; i++) {
- int a, b;
- cin >> a >> b;
- v[i] = { i, {a, b} };
- }
- sort(v.begin(), v.end(), comp);
- set <int> s;
- for (int i = 1; i < 200001; i++)
- s.insert(i);
- vector <int> curr(n, -1);
- vector <int> st;
- long long ans = 0;
- //int c = 0;
- for (int i = 0; i < n; i++) {
- auto t = s.lower_bound(v[i].second.first);
- if (*t == v[i].second.first) {
- //c++;
- s.erase(v[i].second.first);
- curr[v[i].first] = t&;
- //st.push_back(v[i].first);
- v[i].first = -1;
- continue;
- }
- else if (t == s.begin()) {
- if (*t == v[i].second.first) {
- //c++;
- s.erase(v[i].second.first);
- curr[v[i].first] = *t;
- //st.push_back(v[i].first);
- v[i].first = -1;
- }
- else {
- ans += v[i].second.second;
- }
- }
- else {
- t--;
- s.erase(*t);
- curr[v[i].first] = *t;
- //st.push_back(v[i].first);
- v[i].first = -1;
- }
- }
- cout << ans << endl;
- for (int i = 0; i < n; i++)
- cout << curr[i] << " ";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement