1 solutions
-
1
#include<bits/stdc++.h> using namespace std; const int N=10010; struct Stu{ int p,t; }; bool cmp(Stu a,Stu b) { if(a.t<b.t) return 1; if(a.t==b.t&&a.p>b.p) return 1; return 0; } int main() { int n; while(cin>>n) { vector<Stu> v; for(int i=0;i<n;i++) { int p,t; cin>>p>>t; v.push_back({p,t}); } sort(v.begin(),v.end(),cmp); //按照时间从小到大排序 priority_queue<int,vector<int>,greater<int> > q; //存储利润 for(int i=0;i<n;i++) { q.push(v[i].p); //先放入当前元素 if(q.size()>v[i].t) //如果元素个数超过当前的时间了 { q.pop(); } } int ans=0; //累加答案 while(q.size()) { ans+=q.top(); q.pop(); } cout<<ans<<endl; } return 0; }
- 1
Information
- ID
- 167
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 5
- Tags
- # Submissions
- 18
- Accepted
- 5
- Uploaded By