• Educational Codeforces Round 91 (Rated for Div. 2) C. Create The Teams(贪心/排序)


    There are nn programmers that you want to split into several non-empty teams. The skill of the ii -th programmer is aiai . 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 xx .

    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 tt (1≤t≤10001≤t≤1000 ) — the number of test cases.

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

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

    The sum of nn over all inputs does not exceed 105105 .

    Output

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

    Example

    Input

    Copy

    3

    5 10

    7 11 2 9 5

    4 8

    2 4 2 3

    4 11

    1 3 3 7

    Output

    Copy

    2

    1

    0

    首先要把原序列排序。然后就是从小到大排序还是从大到小排序的问题。如果从小到大的话,受限于前面的元素,如果前面的元素很小的话,比如a[1] = 1, x = 100,就浪费了很多大的元素,因此需要从后往前来凑组。用变量记录当前组的成员数,当前组最小值以及答案,O(n)扫一遍即可。

    #include <bits/stdc++.h>
    using namespace std;
    int n, x, a[100005];
    int main()
    {
        int t;
        cin >> t;
        while(t--){
            cin >> n >> x;
            for(int i = 1; i <= n; i++) scanf("%d", &a[i]);
            sort(a + 1, a + n + 1);
            int ans = 0, cnt = 1, mmin = a[n];
            for(int i = n - 1; i >= 0; i--){
                if(mmin * cnt >= x){
                    ans++;
                    mmin = a[i];
                    cnt = 1;
                } else{
                    mmin = a[i];
                    cnt++;
                }
            }
            cout << ans << endl;
        }
     
        return 0;
    }
  • 相关阅读:
    TeamCity+Docker
    k8s 安装步骤
    Gitlab使用时的一些注意事项
    Docker常用命令
    AspNetCore OpenId
    AspNetCore中的IdentityServer4客户端认证模式实现
    AspNet Core 认证
    基于TeamCity的asp.net mvc/core,Vue 持续集成与自动部署
    Cobbler自动化装机脚本
    kubernetes管理机密信息
  • 原文地址:https://www.cnblogs.com/lipoicyclic/p/13297310.html
Copyright © 2020-2023  润新知