A. Boboniu Chats with Du - 枚举 -贪心

A. Boboniu Chats with Du

time limit per test

1 second

memory limit per test

256 megabytes

input

standard input

output

standard output

Have you ever used the chat application QQ? Well, in a chat group of QQ, administrators can muzzle a user for days.

In Boboniu's chat group, there's a person called Du Yi who likes to make fun of Boboniu every day.

Du will chat in the group for nn days. On the ii-th day:

  • If Du can speak, he'll make fun of Boboniu with fun factor aiai. But after that, he may be muzzled depending on Boboniu's mood.
  • Otherwise, Du won't do anything.

Boboniu's mood is a constant mm. On the ii-th day:

  • If Du can speak and ai>mai>m, then Boboniu will be angry and muzzle him for dd days, which means that Du won't be able to speak on the i+1,i+2,⋯,min(i+d,n)i+1,i+2,⋯,min(i+d,n)-th days.
  • Otherwise, Boboniu won't do anything.

The total fun factor is the sum of the fun factors on the days when Du can speak.

Du asked you to find the maximum total fun factor among all possible permutations of aa.

Input

The first line contains three integers nn, dd and mm (1≤d≤n≤105,0≤m≤1091≤d≤n≤105,0≤m≤109).

The next line contains nn integers a1,a2,…,ana1,a2,…,an (0≤ai≤1090≤ai≤109).

Output

Print one integer: the maximum total fun factor among all permutations of aa.

Examples

input

Copy

5 2 11
8 10 15 23 5

output

Copy

48

input

Copy

20 2 16
20 5 8 2 18 16 2 16 16 1 5 16 2 13 6 16 4 17 21 7

output

Copy

195

Note

In the first example, you can set a′=[15,5,8,10,23]a′=[15,5,8,10,23]. Then Du's chatting record will be:

  1. Make fun of Boboniu with fun factor 1515.
  2. Be muzzled.
  3. Be muzzled.
  4. Make fun of Boboniu with fun factor 1010.
  5. Make fun of Boboniu with fun factor 2323.

Thus the total fun factor is 4848.

=========================================================================

把小于等于m这些不会带来禁言的放在一组,把剩下的大于m的放在一组。

然后暴力枚举一下该选几个禁言的,显然需要从大到小更优,而且其安排规则体现了贪心的思想

首先是0个,那么显然是全部小于等于m的累加即可

然后是1个,那么就是在小于等于的集合后面加一个最大的即可

然后是2个,也就是第一个后面放d个做填充,再放第二个。

显然优先用大于m的这些进行填充,然后不够了再用小于等于m的进行填充

# include<bits/stdc++.h>

using namespace std;
# define mod 1000000007
typedef long long int ll;


ll a[100000+10],b[100000+10],suma[100000+10],sumb[100000+10],bac[100000+10];
int lena,lenb;

bool cmp(ll x, ll y)
{
    return x>y;
}
int main ()
{


 int n,d,m;
 cin>>n>>d>>m;

 ll ans=0;
 for(int i=1;i<=n;i++)
 {
     int x;
     cin>>x;
     if(x<=m)
     {
         lenb++;
         b[lenb]=x;

         ans+=x;
     }
     else
     {
         lena++;
         a[lena]=x;
     }
 }

 sort(a+1,a+1+lena,cmp);
 sort(b+1,b+1+lenb,cmp);

 for(int i=1;i<=lena;i++)
 {
     suma[i]=suma[i-1]+a[i];

     //cout<<a[i]<<" ";
 }


 //cout<<endl;


 for(int i=1;i<=lenb;i++)
 {
     sumb[i]=sumb[i-1]+b[i];

    // cout<<b[i]<<" ";
 }


 //cout<<endl;
 for(int i=lenb;i>=1;i--)
 {
     bac[i]=bac[i+1]+b[i];
 }

 for(int cnt=1;cnt<=lena;cnt++)
 {

     int nowneed=(cnt+(cnt-1)*d);


     ll nowa=suma[cnt];
     ll nowkong=(cnt-1)*d;
     //需要这些来填充

     ll cntbac=lena-cnt; //现在有这么多a

     if(cntbac>=nowkong)
     {
         //a是够用的
         ans=max(ans,suma[cnt]+sumb[lenb]);

      //   cout<<cnt<<" "<<suma[cnt]+sumb[lenb]<<" "<<suma[cnt]<<" "<<sumb[lenb]<<endl;
     }
     else
     {

         //a不够用,要拿b一点

         int nowb=nowkong-cntbac;

         if(nowb>lenb)  //b也不够,不整了
            break;



         ans=max(ans,suma[cnt]+sumb[lenb]-bac[lenb-nowb+1]);

         //cout<<cnt<<" "<<suma[cnt]+sumb[lenb]-bac[n-nowb+1]<<" "<<suma[cnt]<<" "<<sumb[lenb]<<" "<<bac[n-nowb+1]<<endl;
     }

 }

 cout<<ans;

    return 0;

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

秦三码

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值