Cattle-off practice match 50 C-tokitsukaze and Soldier

Portal : https://ac.nowcoder.com/acm/contest/1080/C

Meaning of the questions:

There are n individuals, everyone has their own value Vi, but these people are lonely, they can only tolerate a maximum of Si people together. How can together choose the highest human values and.

 

Ideas:

1. First, think of Si to enumerate every individual, naturally think of each person specified a minimum of Si, and then deal with the bottom line of not less than TA people.

2. If every sort, it is foreseeable time out. So before we consider the state can spend.

3. We Si descending order for each individual tolerance. Top with a small heap maintain the chosen people of V, when enumerating backwards, it will pop part of the original top of the heap.

 1 #include<iostream>
 2 #include<cstring>
 3 #include<queue>
 4 #include<algorithm>
 5 #define ll long long
 6 using namespace std;
 7 const int N=100010;
 8 struct node
 9 {
10     ll v,s;
11     friend bool operator <(node x,node y)
12     {
13         return x.s>y.s;
14     }
15 }a[N];
16 priority_queue<int,vector<int>,greater<int> > q;
17 int main()
18 {
19     ios::sync_with_stdio(false);
20     int n;
21     ll sum=0,ans=0;
22     cin>>n;
23     for(int i=0;i<n;i++)
24         cin>>a[i].v>>a[i].s;
25 
26     sort(a,a+n);
27     for(int i=0;i<=n;i++)
28     {
29         q.push(a[i].v);
30         sum+=a[i].v;
31         while(q.size()>a[i].s)
32         {
33             sum-=q.top();
34             q.pop();
35         }
36         ans=max(ans,sum);
37     }
38     cout<<ans<<endl;
39     return 0;
40 }
View Code

 

Guess you like

Origin www.cnblogs.com/g-xf/p/11408517.html