#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 5e5 + 3e2;
#define MP make_pair
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
pair<int, int> a[N];
void check(vector<int> v){
sort(v.begin(), v.end());
if (v[1] - v[0] <= v[2] - v[1]){
cout << a[v[0]].first + a[v[1]].first + a[v[2]].first;
exit(0);
}
}
void solve(){
int n;
cin >> n;
vector<int> perm(n);
for (int i = 1; i <= n; i++){
cin >> a[i].first;
a[i].second = i;
}
sort(a + 1, a + n + 1);
reverse(a + 1, a + n + 1);
int q;
cin >> q;
for (int i = 1; i <= n; i++){
for (int j = i + 1; j <= n; j++){
for (int k = j + 1; k <= n; k++){
check({a[i].second, a[j].second, a[k].second});
}
}
}
}
int main(){
ios_base::sync_with_stdio(false);
//freopen("output.txt", "w", stdout);
int tests = 1;
// cin >> tests;
while (tests--){
solve();
}
return 0;
}
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Incorrect |
54 ms |
2664 KB |
Output isn't correct |
2 |
Halted |
0 ms |
0 KB |
- |
# |
결과 |
실행 시간 |
메모리 |
Grader output |
1 |
Correct |
1 ms |
204 KB |
Output is correct |
2 |
Incorrect |
1 ms |
204 KB |
Output isn't correct |
3 |
Halted |
0 ms |
0 KB |
- |