-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy path1253C.cpp
More file actions
45 lines (42 loc) · 752 Bytes
/
1253C.cpp
File metadata and controls
45 lines (42 loc) · 752 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
41
42
43
44
45
//21171_somesh || asomesh999
//AC
#include<bits/stdc++.h>
using namespace std;
#define fr(i,a,b) for(long long i=a;i<b;i++)
#define io ios::sync_with_stdio(false);cin.tie(NULL);
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
long int mod=1000000007;
int main()
{
io
int n, m;
cin >> n >> m;
vl arr(n);
vl pref(n);
ll sum = 0;
fr(i, 0, n) {
cin >> arr[i];
}
sort(arr.begin(), arr.end());
fr(i, 0, n) {
sum += arr[i];
pref[i] = sum;
}
vl ans(n);
fr(i, 0, n) {
if (i <= m - 1) {
ans[i] = pref[i];
} else {
ans[i] = pref[i - 1] + arr[i] + ans[i - m];
}
}
for (auto it : ans) {
cout << it << ' ';
}
return 0;
}