Precreation contest files
This commit is contained in:
35
misc/binary-search/ghepcap.cpp
Normal file
35
misc/binary-search/ghepcap.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int a[100000];
|
||||
|
||||
int main() {
|
||||
ios_base::sync_with_stdio(false);
|
||||
cin.tie(NULL);
|
||||
freopen("ghepcap.inp", "r", stdin);
|
||||
|
||||
int n;
|
||||
cin >> n;
|
||||
for (int i = 0; i < n; i++)
|
||||
cin >> a[i];
|
||||
sort(a, a + n);
|
||||
// 89 90 91 99 100 101
|
||||
int res = 0;
|
||||
for (int j = 0; j < n; j++) {
|
||||
int l = 0, r = j;
|
||||
// int ans = a[n - 1];
|
||||
while (l < r) {
|
||||
int mid = (l + r) / 2;
|
||||
if (10 * a[mid] < a[j] * 9) {
|
||||
l = mid + 1;
|
||||
} else {
|
||||
r = mid;
|
||||
// ans = min(ans, mid);
|
||||
}
|
||||
}
|
||||
// res += j - ans;
|
||||
res += j - l;
|
||||
}
|
||||
cout << res << '\n';
|
||||
}
|
||||
Reference in New Issue
Block a user