Educational Codeforces Round 91 (Rated for Div. 2)C. Create The Teams【贪心】

题目

传送门
There are n programmers that you want to split into several non-empty teams. The skill of the i-th programmer is ai. You want to assemble the maximum number of teams from them. There is a restriction for each team: the number of programmers in the team multiplied by the minimum skill among all programmers in the team must be at least x.

Each programmer should belong to at most one team. Some programmers may be left without a team.

Calculate the maximum number of teams that you can assemble.

Input
The first line contains the integer t (1≤t≤1000) — the number of test cases.

The first line of each test case contains two integers n and x (1≤n≤105;1≤x≤109) — the number of programmers and the restriction of team skill respectively.

The second line of each test case contains n integers a1,a2,…,an (1≤ai≤109), where ai is the skill of the i-th programmer.

The sum of n over all inputs does not exceed 105.

Output
For each test case print one integer — the maximum number of teams that you can assemble.

题意:t组样例,开头两个数n,m,分别表示程序员的数量和要分成一组时这组程序猿中能力的最小值乘以这组程序员的数量的最小值m,下面是n个数表示每个程序员的能力值,问你最多能分成几组

思路:本来想着用dp来着想了好大一会没写出来,参考的大佬博客之后发现是贪心,我真是太菜了…我们把数组从大到小排列,一直增加人数直到能分成一组为止,具体看代码

#include<iostream>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<sstream>
#include<queue>
#include<stack>
using namespace std;
#define ll long long
ll a[120000];
int t,n,m;
int cmp(int x,int y)//从大到小
{
    return x>y;
}
void solve()
{
    for(int i=0;i<n;i++)
       cin>>a[i];
    sort(a,a+n,cmp);
    ll sum=0,s=1;
    for(int i=0;i<n;i++)
    {
        if(a[i]*s>=m)
        {
            s=1;//程序员的数量
            sum++;
        }
        else s++;
    }
    printf("%lld\n",sum);
}
int main()
{
      cin>>t;
      while(t--)
      {
          cin>>n>>m;
          solve();
      }
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值