-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1690_e.cpp
More file actions
40 lines (37 loc) · 764 Bytes
/
1690_e.cpp
File metadata and controls
40 lines (37 loc) · 764 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
void solve(){
int N; ll K;cin>>N>>K;
vector<pair<ll,ll>> arr;
for (int i = 0; i < N; i++) {
ll a; cin >> a;
arr.push_back({a%K, a});
}
sort(arr.begin(), arr.end());
ll result = 0;
int l = 0, r = N-1;
while (l < r) {
auto [a,b] = arr[l];
auto [c,d] = arr[r];
if (a+c<K) {
d = arr[l+1].second;
l++;
r++;
}
result += (b+d)/K;
l++,r--;
}
cout << result;
}
int main()
{
cin.tie(0)->sync_with_stdio(false);
int T = 1;
cin >> T;
while (T--) {
solve();
cout << '\n';
}
return 0;
}