fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3.  
  4. int main() {
  5. int n ;
  6. cin>>n ;
  7. vector <int> b ;
  8. int i = 0 ;
  9. while(i<n){
  10. int x ; cin>>x ;
  11. b.push_back(x);
  12. i++;
  13. }
  14. sort(b.begin(), b.end());
  15. int t;cin>>t;
  16. int l=0, r=b.size();
  17. while(l<r){
  18. int m=(l+r)/2;
  19. if(b[m]<=t) l=m+1;
  20. else{
  21. r=m;
  22. }
  23. }
  24. cout<<b[l];// return element just greater than target
  25. return 0;
  26. }
Success #stdin #stdout 0s 5284KB
stdin
5
1 2 3 4 5
3
stdout
4