1 条题解

  • 1
    @ 2024-6-4 19:19:55
    #include <bits/stdc++.h>
    #define ll long long
    #define IOS ios::sync_with_stdio(false), cin.tie(0), cout.tie(0)
    using namespace std;
    int n, k;
    ll ans, x;
    struct T
    {
        ll w, h;
    };
    bool operator <(T a, T b)   
    {
        if (a.w != b.w)
            return a.w > b.w;  
        return a.h > b.h;
    }
    priority_queue<T> q;
    int main()
    {
        IOS; 
        cin >> n >> k;
        for (int i = 1; i <= n; i++)
        {
            cin >> x;
            q.push({x, 1}); 
        }
        if ((n - 1) % (k - 1) != 0)  
            for (int i = 1; i <= k - 1 - (n - 1) % (k - 1); i++)
                q.push({0, 1}); 
        while (q.size() != 1)
        {
            T tmp;
            ll sum = 0, maxn = 0;
            for (int i = 1; i <= k; i++)  
            {
                tmp = q.top();
                sum += tmp.w;  
                maxn = max(maxn, tmp.h);  
                q.pop();
            }
            ans += sum;  
            q.push({sum, maxn + 1});  
        }
        cout << ans << endl << q.top().h - 1 << endl;  
        return 0;
    }
    

    过了哈,放心食用

    • 1

    信息

    ID
    426
    时间
    1000ms
    内存
    256MiB
    难度
    10
    标签
    递交数
    4
    已通过
    3
    上传者