-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcomB_1125.cpp
More file actions
55 lines (44 loc) · 1.01 KB
/
comB_1125.cpp
File metadata and controls
55 lines (44 loc) · 1.01 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
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
int solve(int x[], int n) // 2021136089 À̰ü¿ì
{
int min{std::numeric_limits<int>::max()};
int result;
for(int i{0}; i<n; ++i) {
for(int j{i+1}; j<n; ++j) {
if(x[i]>=x[j]) continue;
for(int k{j+1}; k<n; ++k) {
if(x[j]<=x[k]) continue;
result=x[i]+x[j]+x[k];
if(result<min) min=result;
}
}
}
return (min==std::numeric_limits<int>::max() ? -1 : min);
}
int main()
{
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
std::cout.tie(nullptr);
int T;
std::cin >> T;
int n;
int result[100];
for (int t{0}; t < T; ++t)
{
std::cin>>n;
int x[200]{};
for(int i{0}; i<n; ++i) {
std::cin>>x[i];
result[t]=solve(x, n);
}
}
for (int t{0}; t < T; ++t)
{
std::cout <<result[t] << '\n';
}
return 0;
}