Solution
2024-01-03 19:49:06
发布于:广东
0阅读
0回复
0点赞
#include <bits/stdc++.h>
using namespace std;
#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"
typedef long long ll;
typedef long double ld;
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();
return 0;
}
这里空空如也
有帮助,赞一个