Solution Of CF2032C Trinity
Preface
赛场解法和官解写法有一点不一样,发一篇。
Solution
我们注意到本题的要求与下标无关,只与具体的
我们对
那么我们对于每个
时间复杂度
Code
#include <bits/stdc++.h>
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(NULL), cout.tie(NULL);
int T; cin >> T;
for (int n; T --; ) {
cin >> n;
vector <int> a(n);
for (int i = 0; i < n; i ++) cin >> a[i];
sort (a.begin(), a.end());
int ans = n - 1;
for (int i = 0; i + 1 < n; i ++) {
int x = lower_bound(a.begin(), a.end(), a[i] + a[i + 1]) - a.begin();
ans = min(n - x + i, ans);
}
cout << ans << '\n';
}
return 0;
}