Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <queue>
- #include <iostream>
- #include <algorithm>
- using namespace std;
- #define long long long
- #define f1(i,n) for (int i=1; i<=n; i++)
- #define f0(i,n) for (int i=0; i<n; i++)
- #define N 100005
- int n, Index[N], Time[N], Cost[N];
- priority_queue<int> qu;
- bool cmp(int x, int y){
- if (Time[x]!=Time[y]) return Time[x]>Time[y];
- return Cost[x]>Cost[y];
- }
- main(){
- scanf("%d", &n);
- f1(i,n) scanf("%d%d", &Time[i], &Cost[i]);
- f1(i,n) Index[i]=i;
- sort(Index+1, Index+n+1, cmp);
- int Pos=1, ThisTime=1000000000;
- long Sum = 0;
- while (ThisTime!=0) {
- while (Pos<=n && Time[Index[Pos]]==ThisTime)
- qu.push(Cost[Index[Pos]]), Pos++;
- if (qu.size()) { Sum+=qu.top(); qu.pop(); }
- ThisTime--;
- if (qu.empty()) ThisTime=Time[Index[Pos]]; // Time[0]=0
- }
- cout << Sum << endl;
- }
Advertisement
Add Comment
Please, Sign In to add comment