题解
2023-08-26 17:49:22
发布于:广东
2阅读
0回复
0点赞
沙发!
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define mpa make_pair
#define pb push_back
#define ins insert
#define f first
#define s second
#define all(x) x.begin(), x.end()
#define nl "\n"
int MOD = 1;
bool cmp(int &a, int &b) {
return (a % MOD) > (b % MOD);
}
void solve() {
int N, K;
cin >> N >> K;
vector<int> A(N);
int maxD = 0;
for (int i = 0; i < N; i++) {
cin >> A[i];
maxD = max(maxD, A[i]);
}
int mx = 0;
for (int i = 1; i <= maxD; i++) {
int amount = 0;
for (int j = 0; j < N; j++) { amount += A[j] / i; }
if (amount < K / 2) { continue; }
if (amount >= K) {
mx = max(mx, (K / 2) * i);
continue;
}
MOD = i;
sort(all(A), cmp);
int cur = (amount - K / 2) * i;
for (int j = 0; j < N && j + amount < K; j++) { cur += A[j] % i; }
mx = max(mx, cur);
}
cout << mx << nl;
}
int main() {
cout.sync_with_stdio(false);
cout.tie(0);
solve();
}
这里空空如也
有帮助,赞一个