CF 797, got stuck on E and had to leave, went pretty well

This commit is contained in:
2022-06-07 21:38:41 +02:00
parent a2acadbf3e
commit 6de228cf8a
7 changed files with 346 additions and 0 deletions

View 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;
}