小号@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原因即可免费领取关注哦