CF789D Mike and distribution

题目连接

一道人类智慧题。。。。

这道题目可以转化为在a,b中的选出一些位置,使得这些位置处的值加起来大于没有选的位置的值

我们按照a的权值排序,选择第一个元素,其与元素两两分组,每组选择b更大的那一个

很显然这样对于数组b是满足要求的,然后我们发现第i组的a权值肯定大于第i+1组的没有选的位置的权值,

在加上我们选择了第一个元素,所以a数组也是满足要求的

 

# include<iostream>
# include<cstdio>
# include<cmath>
# include<cstring>
# include<algorithm>
using namespace std;
const int mn = 1e5 + 10;
int n,m,ans[mn],tot;
struct node{int a,b,pos;};
node da[mn];
bool cmp(node x,node y)
{
    return x.a>y.a;
}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&da[i].a),da[i].pos=i;
    for(int i=1;i<=n;i++)
        scanf("%d",&da[i].b);
    sort(da+1,da+1+n,cmp);
    ans[++tot]=da[1].pos;
    for(int i=2;i<=n;i+=2)
    {
        if(i==n)
        {
            ans[++tot]=da[i].pos;
            break;
        }
        if(da[i].b>da[i+1].b) ans[++tot]=da[i].pos;
        else ans[++tot]=da[i+1].pos;
    }
    printf("%d\n",tot);
    for(int i=1;i<=tot;i++)
        printf("%d ",ans[i]);
    return 0;
}

 

转载于:https://www.cnblogs.com/logeadd/p/9528030.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值