Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <bitset>
- #include <vector>
- #include <queue>
- #include <algorithm>
- #include <map>
- using namespace std;
- int main() {
- int n;
- cin >> n;
- vector<pair<int,int>> vec;
- vec.reserve(n);
- int maxx = 0;
- for(int i =0 ;i < n; ++i){
- int time, value;
- cin >> time >> value;
- maxx = max(time,maxx);
- vec.push_back({time,value});
- }
- sort(vec.begin(),vec.end(),[&](const pair<int,int>& a, const pair<int,int>& b){
- if (a.first == b.first){
- return a.second > b.second;
- }else{
- return a.first < b.first;
- }
- });
- long long ans = 0;
- vector<int> ansv(maxx+1,0);
- for(int i = 1 ; i <= maxx; ++i){
- auto it = lower_bound(vec.begin(),vec.end(),i,[&](const pair<int,int>& a, int b){
- return a.first < b;
- });
- if(it != vec.end()) {
- ansv[i] =it->second;
- vec.erase(it);
- }
- }
- for(int i = 0; i < vec.size(); ++i){
- int l = 1, r = vec[i].first;
- int minn_index = -1, minn = 1000000000;
- for(;l < r+1; ++l){
- if(ansv[l] < minn){
- minn = ansv[l];
- minn_index =l;
- }
- }
- if(minn < vec[i].second){
- ansv[minn_index] = vec[i].second;
- }
- }
- for(auto it: ansv){
- ans += it;
- }
- cout << ans << '\n';
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement