Submission
Status:
---P------
Subtask/Task Score:
10/100
Score: 10
User: Kidmaiok
Problemset: ประลอง
Language: cpp
Time: 0.002 second
Submitted On: 2025-10-07 14:05:02
#include<bits/stdc++.h>
using namespace std;
int main(){
int n, pp;
cin >> n;
vector<int> people;
for(int i = 0; i < n; i++){
cin >> pp;
people.push_back(pp);
}
// Sort in descending order for greedy approach
sort(people.begin(), people.end(), greater<int>());
vector<int> t1, t2;
int sum1 = 0, sum2 = 0;
int size1 = 0, size2 = 0;
int target1 = (n + 1) / 2; // Team 1 size (larger if odd)
int target2 = n / 2; // Team 2 size
// Greedy assignment: alternate between teams, choosing to balance sums
for(int val : people){
// If team sizes not yet filled, assign to balance
if(size1 < target1 && (size2 >= target2 || sum1 <= sum2)){
t1.push_back(val);
sum1 += val;
size1++;
} else {
t2.push_back(val);
sum2 += val;
size2++;
}
}
// Output in original order (scan original array)
sort(people.begin(), people.end(), greater<int>());
for(int val : t1)
cout << val << ' ';
cout << '\n';
for(int val : t2)
cout << val << ' ';
cout << '\n';
return 0;
}