-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathC_Odd_Process.cpp
More file actions
72 lines (60 loc) · 1.35 KB
/
C_Odd_Process.cpp
File metadata and controls
72 lines (60 loc) · 1.35 KB
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <bits/stdc++.h>
using namespace std;
#define int long long
void solve() {
int n;
cin >> n;
vector<int> v(n);
vector<int> t1, t2;
for(int i=0;i<n;i++) {
cin >> v[i];
if(v[i] & 1) t1.push_back(v[i]);
else t2.push_back(v[i]);
}
sort(t1.begin(), t1.end());
sort(t2.rbegin(), t2.rend());
if(t1.size() == 0) {
for(int i=0;i<n;i++) cout << "0 ";
cout << "\n";
return;
}
int m = t2.size();
if(m == 0) {
for(int i=0;i<n;i++) {
cout << ((i&1) ? 0 : t1.back()) << " ";
}
cout << "\n";
return;
}
for(int i=1;i<m;i++) t2[i] += t2[i-1];
cout << t1.back() << " ";
for(int i=0;i<m;i++) {
cout << (t1.back() + t2[i]) << " ";
}
for(int k=m + 2;k <= n;k++) {
int x = k - (m + 1); // odd needed
int prs = (x + 1) / 2;
if(2 * prs > t1.size() - 1) {
cout << "0 ";
continue;
}
if(x % 2 == 0) {
cout << (t1.back() + t2[m-1]) << " ";
}
else {
cout << (t1.back() + (m > 1 ? t2[m-2] : 0)) << " ";
}
}
cout << "\n";
}
int32_t main(){
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
int _;
cin >> _;
while (_-->0) {
solve();
}
return 0;
}