-
Notifications
You must be signed in to change notification settings - Fork 14
Expand file tree
/
Copy path1456Supermarket.cpp
More file actions
37 lines (36 loc) · 829 Bytes
/
1456Supermarket.cpp
File metadata and controls
37 lines (36 loc) · 829 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#include <iostream>
#include <vector>
#include <stdio.h>
#include <utility>
#include <queue>
#include <stack>
#include <algorithm>
#include <set>
using namespace std;
const int N = 10010;
int n;
vector<int> profit[N];
int main(){
while(scanf("%d",&n)!=EOF){
int max_d = 0;
int p,d;
for(int i=0;i<N;i++)
profit[i].clear();
for(int i=0;i<n;i++){
scanf("%d%d",&p,&d);
profit[d].push_back(p);
max_d = max(max_d,d);
}
priority_queue<int> pq;
int best = 0;
for(d=max_d;d>=1;d--){
for(int i=0;i<profit[d].size();i++){
pq.push(profit[d][i]);
}
if(pq.empty()) continue;
best += pq.top();
pq.pop();
}
printf("%d\n",best);
}
}