Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- #define NMAX 100000
- int n, v[NMAX], p[NMAX];
- void read() {
- cin >> n;
- for (int i = 1; i <= n; i++)
- cin >> v[i];
- }
- void sort() {
- for (int i = 1; i < n; i++)
- for (int j = i + 1; j <= n; j++)
- if (v[j] < v[i])
- swap(v[j], v[i]);
- }
- void greedy() {
- int sum = 0;
- for (int i = 1; i <= n; i++)
- sum += v[i];
- sum /= 2;
- for (int i = 1; i <= n; i++)
- if (sum - v[i] >= 0) {
- p[i] = 1;
- sum -= p[i];
- }
- }
- void tipar() {
- for (int i = 1; i <= n; i++)
- if (p[i])
- cout << v[i] << ' ';
- cout << endl;
- for (int i = 1; i <= n; i++)
- if (!p[i])
- cout << v[i] << ' ';
- }
- int main() {
- read();
- sort();
- greedy();
- tipar();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement