CF 797, got stuck on E and had to leave, went pretty well
This commit is contained in:
76
codeforces/rounds/797/e.cpp
Normal file
76
codeforces/rounds/797/e.cpp
Normal file
@@ -0,0 +1,76 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
void test_case(int tc){
|
||||
int n, k;
|
||||
|
||||
cin >> n >> k;
|
||||
|
||||
vector<vector<int>> modulos(k);
|
||||
|
||||
for(int i = 0; i < n; ++i){
|
||||
int s;
|
||||
cin >> s;
|
||||
|
||||
modulos[s % k].push_back(s);
|
||||
}
|
||||
|
||||
for(auto v : modulos){
|
||||
sort(v.begin(), v.end());
|
||||
}
|
||||
|
||||
unsigned long long result = 0;
|
||||
|
||||
for(int i = k - 1; i > 0; i--){
|
||||
while(!modulos[i].empty() && !modulos[k-i].empty()){
|
||||
int a = modulos[i].back(), b = modulos[k - 1].back();
|
||||
modulos[i].pop_back();
|
||||
modulos[k-1].pop_back();
|
||||
|
||||
result += (a + b) / k;
|
||||
}
|
||||
}
|
||||
|
||||
while(modulos[0].size() > 1){
|
||||
int a = modulos[0].back();
|
||||
modulos[0].pop_back();
|
||||
int b = modulos[0].back();
|
||||
modulos[0].pop_back();
|
||||
|
||||
result += (a + b) / k;
|
||||
}
|
||||
|
||||
for(int i = 0; i < k; ++i){
|
||||
for(int j = i + 1; j < k; ++j){
|
||||
while(!modulos[i].empty() && !modulos[j].empty()){
|
||||
int a = modulos[i].back(), b = modulos[j].back();
|
||||
modulos[i].pop_back();
|
||||
modulos[j].pop_back();
|
||||
|
||||
result += (a + b) / k;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cout << result << '\n';
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main(){
|
||||
ios::sync_with_stdio(0);
|
||||
cin.tie(0);
|
||||
|
||||
int t;
|
||||
cin >> t;
|
||||
|
||||
for(int tc = 1; tc <= t; ++tc){
|
||||
test_case(tc);
|
||||
}
|
||||
|
||||
cout << flush;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user