2015-2016 Petrozavodsk Winter Training Camp, SPb SU + SPb AU Contest Greedy Game
程序员文章站
2022-05-22 10:50:25
...
题意:一个物品有ai和bi两种价值,如果a拿了,价值就是ai,b拿了,价值就是bi,现在ab都要让自己能拿的价值最大,问:无论a怎么拿,b能拿到的最大价值最少是多少
#include<stdio.h>
#include<algorithm>
#include<queue>
using namespace std;
#define ll long long
struct node{
ll a,b;
};
node x[100005];
bool cmp(node w,node e){
if(w.a==e.a){
return w.b>e.b;
}
else
return w.a>e.a;
}
priority_queue<ll,vector<ll>,greater<ll> >q;
ll h[100005];
int main(){
ll n;
while(scanf("%lld",&n)!=EOF){
for(ll i=1;i<=n;i++){
ll temp;
scanf("%lld",&temp);
x[i].a=temp;
}
for(ll i=1;i<=n;i++){
scanf("%lld",&h[i]);
x[i].b=h[i];
}
if(n==1){
printf("0\n");
continue;
}
sort(x+1,x+n+1,cmp);
int flaga=1,flagb=1;
q.push(x[2].b);
for(int i=3;i<=n;i++){
if(flagb<flaga){
q.push(x[i].b);
flagb++;
}
else{
if(x[i].b>q.top()){
q.pop();
q.push(x[i].b);
}
flaga++;
}
}
ll ans=0;
while(!q.empty()){
ans=ans+q.top();
q.pop();
}
printf("%lld\n",ans);
}
}
上一篇: Intersecting Lines
下一篇: [Gym] - 100886K 2015-2016 Petrozavodsk Winter Training Camp, Saratov SU Contest K - Toll Roads
推荐阅读
-
2015-2016 Petrozavodsk Winter Training Camp, SPb SU + SPb AU Contest Greedy Game
-
[Gym] - 100886K 2015-2016 Petrozavodsk Winter Training Camp, Saratov SU Contest K - Toll Roads
-
Gym - 100886I 2015-2016 Petrozavodsk Winter Training Camp, Saratov SU Contest I - Archaeological Res
-
Gym - 100886B 2015-2016 Petrozavodsk Winter Training Camp, Saratov SU Contest B - Game on Bipartite
-
2015-2016-petrozavodsk-winter-training-camp-spb-su-spb-au-contest F-Colored Path(状压DP)
-
2015-2016 Petrozavodsk Winter Training Camp, Moscow SU Trinity Contest(Gym 100962)
-
Gym - 100886F 2015-2016 Petrozavodsk Winter Training Camp, Saratov SU Contest F - Empty Vessels
-
2015-2016 Petrozavodsk Winter Training Camp, Nizhny Novgorod SU Contest (5/9)
-
题解:2015-2016 Petrozavodsk Winter Training Camp, Saratov SU Contest