Đăng nhập để hỏi chi tiết


Nay mình khởi động tí nha mấy ac, contest 08 luyện thi HSG:
Hãy luôn nhớ cảm ơn và vote 5*
nếu câu trả lời hữu ích nhé!
//duyanhle310
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const int N = 1e5 + 5;
ll a[N],total[2],cnt[2];
int main(){
cin.tie(NULL);
ios::sync_with_stdio(false);
cnt[0] = 0;cnt[1] = 0;
total[0] = 0;total[1] = 0;
int n,k;cin >> n >> k;
for (int i = 0 ; i < n; ++i)cin >> a[i];
sort(a,a+n,greater<int>());
for (int i = 0; i < n; ++i){
if (cnt[a[i] % 2] >= k) continue;
++cnt[ a[i] % 2];
total[a[i]%2] += a[i];
}
if (cnt[0] < k && cnt[1] < k) cout<<0;
else cout<< max({total[0],total[1],0LL});
return 0;
}Hãy giúp mọi người biết câu trả lời này thế nào?

Bảng tin
