Changed the folder structure of codeforces problemsets
This commit is contained in:
55
codeforces/problemsets/interestingDrink/a.cpp
Normal file
55
codeforces/problemsets/interestingDrink/a.cpp
Normal file
@@ -0,0 +1,55 @@
|
||||
#include <bits/stdc++.h>
|
||||
|
||||
using namespace std;
|
||||
|
||||
int main(){
|
||||
ios::sync_with_stdio(0);
|
||||
cin.tie(0);
|
||||
|
||||
int n, q, xi, mi;
|
||||
cin >> n;
|
||||
|
||||
vector<int> xs;
|
||||
xs.reserve(n);
|
||||
|
||||
for(int i = 0; i < n; ++i){
|
||||
cin >> xi;
|
||||
xs.push_back(xi);
|
||||
}
|
||||
sort(xs.begin(), xs.end());
|
||||
|
||||
cin >> q;
|
||||
for(int qi = 0; qi < q; ++qi){
|
||||
cin >> mi;
|
||||
|
||||
if(mi >= xs.back()){
|
||||
cout << n << "\n";
|
||||
continue;
|
||||
}
|
||||
if(mi < xs.front()){
|
||||
cout << "0\n";
|
||||
continue;
|
||||
}
|
||||
|
||||
int start = 0, end = n - 1;
|
||||
int middle = (end + start) / 2;
|
||||
|
||||
while(middle != start && middle != end){
|
||||
if(mi > xs[middle]){
|
||||
start = middle + 1;
|
||||
} else{
|
||||
end = middle;
|
||||
}
|
||||
middle = (end + start) / 2;
|
||||
}
|
||||
if(mi < xs[middle]){
|
||||
cout << middle << "\n";
|
||||
} else{
|
||||
cout << middle + 1 << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
cout << flush;
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user