fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main() {
  4. ios::sync_with_stdio(false);
  5. cin.tie(0), cout.tie(0);
  6. int n; cin >> n;
  7. long long a[n+1];
  8. a[0]=-1;
  9. for(int i=1;i<=n;i++) cin >> a[i];
  10. sort(a+1,a+n+1);
  11. int q; cin >> q;
  12. while(q--) {
  13. long long x; cin >> x;
  14. int j=upper_bound(a+1,a+n+1,x)-a;
  15. if(j==n+1 || a[j]>x) j--;
  16. cout << a[j] << '\n';
  17. }
  18. return 0;
  19. }
Success #stdin #stdout 0s 5292KB
stdin
10
1 11 3 4 7 6 5 8 9 10
2 2
12
stdout
1
11