题解 | #小欧的选数乘积#
小欧的选数乘积
https://www.nowcoder.com/practice/a94f523ebe424d0481533dc9e6138724
我们发现题目所描述的 a 数组就是一个set
每次一定优先乘最大的那个数,所有可以用greater<int>来让set从大到小存储,然后直接遍历即可
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 2e5 + 5;
int __t = 1, n, x, y, a;
set<int, greater<int>> st;
void solve() {
cin >> x >> y >> n;
for (int i = 0; i < n; i++) {
cin >> a;
st.insert(a);
}
if (x >= y) {
cout << 0 << '\n';
return;
}
int ans = 0;
for (auto a : st) {
x *= a, ans++;
if (x >= y) {
cout << ans << '\n';
return;
}
}
cout << -1 << '\n';
return;
}
int32_t main() {
#ifdef ONLINE_JUDGE
ios::sync_with_stdio(false);
cin.tie(0);
#endif
// cin >> __t;
while (__t--)
solve();
return 0;
}

网易游戏公司福利 548人发布