forked from ngthanhtrung23/CompetitiveProgramming
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathH.cpp
More file actions
125 lines (108 loc) · 3.47 KB
/
H.cpp
File metadata and controls
125 lines (108 loc) · 3.47 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
#include <bits/stdc++.h>
#define int long long
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; ++i)
#define FORD(i,a,b) for(int i=(a),_b=(b); i>=_b; --i)
#define REP(i,a) for(int i=0,_a=(a); i < _a; ++i)
#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR(A,n) { cout << #A << " = "; FOR(_,1,n) cout << A[_] << ' '; cout << endl; }
#define PR0(A,n) { cout << #A << " = "; REP(_,n) cout << A[_] << ' '; cout << endl; }
#define sqr(x) ((x) * (x))
#define ll long long
#define __builtin_popcount __builtin_popcountll
#define SZ(x) ((int) (x).size())
using namespace std;
double safe_sqrt(double x) {
return sqrt(max(0.0,x));
}
int GI(int& x) {
return scanf("%lld", &x);
}
int n, k;
struct V {
int x, y, z;
V() {}
V(int x, int y, int z) : x(x), y(y), z(z) {}
V operator + (const V& a) const {
return V(x+a.x, y+a.y, z+a.z);
}
int len() {
return x*x + y*y + z*z;
}
} v[44];
#undef int
int main() {
#define int long long
ios :: sync_with_stdio(0); cin.tie(0);
cout << (fixed) << setprecision(9);
int ntest; cin >> ntest;
while (ntest--) {
cin >> n >> k;
FOR(i,1,n) cin >> v[i].x >> v[i].y >> v[i].z;
int bestsum = 0;
vector<int> res;
if (k == 1) {
FOR(a,1,n) {
V cur = v[a];
if (cur.len() > bestsum) {
bestsum = cur.len();
res = vector<int> {a};
}
}
}
else if (k == 2) {
FOR(a,1,n) FOR(b,a+1,n) {
V cur = v[a] + v[b];
if (cur.len() > bestsum) {
bestsum = cur.len();
res = vector<int> {a, b};
}
}
}
else if (k == 3) {
FOR(a,1,n) FOR(b,a+1,n) FOR(c,b+1,n) {
V cur = v[a] + v[b] + v[c];
if (cur.len() > bestsum) {
bestsum = cur.len();
res = vector<int> {a, b, c};
}
}
}
else if (k == 4) {
FOR(a,1,n) FOR(b,a+1,n) FOR(c,b+1,n) FOR(d,c+1,n) {
V cur = v[a] + v[b] + v[c] + v[d];
if (cur.len() > bestsum) {
bestsum = cur.len();
res = vector<int> {a, b, c, d};
}
}
}
else {
FOR(a,1,n) FOR(b,a+1,n) FOR(c,b+1,n) FOR(d,c+1,n) {
vector< pair<int,int> > cur;
V X = v[a] + v[b] + v[c] + v[d];
FOR(e,1,n) if (e != a && e != b && e != c && e != d) {
V t = X + v[e];
cur.emplace_back(t.len(), e);
}
sort(cur.begin(), cur.end(), greater< pair<int,int> > ());
vector<int> t;
t.push_back(a);
t.push_back(b);
t.push_back(c);
t.push_back(d);
REP(i,k-4) t.push_back(cur[i].second);
X = V(0, 0, 0);
for(auto i : t)
X = X + v[i];
if (X.len() > bestsum) {
bestsum = X.len();
res = t;
}
}
}
cout << bestsum << endl;
sort(res.begin(), res.end());
for(auto x : res) cout << x << ' ';
cout << endl;
}
}