来来来,免费领关注喽!!
查看原帖
来来来,免费领关注喽!!
741580
niuqichongtian楼主2025/1/20 21:14

小号@ikunyyh

#include <bits/stdc++.h>
using namespace std;
#define int long long

const int maxn = 2e5+7;
inline int get(int cnt, int prc) {
    return (cnt + (cnt-1)) * prc;
}
struct node {
    int cnt;
    int pri;
};
struct cmp{
    bool operator()(const node &x, const node &y) const {
        return get(x.cnt, x.pri) > get(y.cnt, y.pri);
    }
};
int N, M;
priority_queue<node, vector<node>, cmp > a;

signed main(signed argc, char const *argv[]) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    node u;
    u.cnt = 1;
    cin >> N >> M;
    for (int i = 1; i <= N; ++i) {
        cin >> u.pri;
        a.push(u);
    }
    // cout << get(1, 9) << endl;
    int ans=0;
    while (M > 0) {
        u = a.top();
        a.pop();
        M -= get(u.cnt, u.pri);
        if (M < 0) break;
        ans++;
        u.cnt++;
        a.push(u);
    }
    cout << ans << endl;
    return 0;
}

注:只要说出TLE原因即可免费领取关注哦

2025/1/20 21:14
加载中...