forked from sitz/UVa-Online-Judge
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path10037.cpp
91 lines (88 loc) · 2.13 KB
/
10037.cpp
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <bits/stdc++.h>
using namespace std;
vector<int> people;
int main()
{
int temp;
bool first = true;
int st;
int N, total;
int s1, s2;
scanf("%d", &N);
scanf("\n");
for (int i = 0; i < N; i++)
{
people.clear();
scanf("%d", &st);
for (int j = 0; j < st; j++)
{
scanf("%d", &temp);
people.push_back(temp);
}
if (first)
{
first = false;
}
else
{
putchar(10);
}
sort(people.begin(), people.end());
if (st == 1)
{
printf("%d\n%d\n", people[0], people[0]);
continue;
}
else if (st == 2)
{
printf("%d\n%d %d\n", people[1], people[0], people[1]);
continue;
}
total = 0;
if (st % 2 == 0)
{
for (int j = 1; j < st / 2; j++)
{
int score = min(people[2 * j + 1] + people[0] + people[1] * 2, people[0] * 2 + people[2 * j] + people[2 * j + 1]);
total += score;
}
total += people[1];
printf("%d\n", total);
for (int j = st / 2 - 1; j > 0; j--)
{
if (people[2 * j + 1] + people[0] + people[1] * 2 <= people[0] * 2 + people[2 * j] + people[2 * j + 1])
{
printf("%d %d\n%d\n%d %d\n%d\n", people[0], people[1], people[0], people[2 * j], people[2 * j + 1], people[1]);
}
else
{
printf("%d %d\n%d\n%d %d\n%d\n", people[0], people[2 * j + 1], people[0], people[0], people[2 * j], people[0]);
}
}
printf("%d %d\n", people[0], people[1]);
}
else if (st % 2 == 1)
{
for (int j = 2; j <= st / 2; j++)
{
int score = min(people[2 * j] + people[0] + people[1] * 2, people[0] * 2 + people[2 * j] + people[2 * j - 1]);
total += score;
}
total += people[1] + people[0] + people[2];
printf("%d\n", total);
for (int j = st / 2; j > 1; j--)
{
if (people[2 * j] + people[0] + people[1] * 2 < people[0] * 2 + people[2 * j] + people[2 * j - 1])
{
printf("%d %d\n%d\n%d %d\n%d\n", people[0], people[1], people[0], people[2 * j - 1], people[2 * j], people[1]);
}
else
{
printf("%d %d\n%d\n%d %d\n%d\n", people[0], people[2 * j - 1], people[0], people[0], people[2 * j], people[0]);
}
}
printf("%d %d\n%d\n%d %d\n", people[0], people[1], people[0], people[0], people[2]);
}
}
return 0;
}