Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- int main()
- {
- int n, q, k;
- cin>>n;
- int a[n];
- for (int i=0; i<n; i++) {
- cin>>a[i];
- }
- cin>>q;
- while (q--) {
- int s=-1, t=-1;
- cin>>k;
- for (int i=0; i<n; i++) {
- if (a[i]<k)
- s=a[i];
- }
- for (int i=n-1; i>=0; i--) {
- if (a[i]>k)
- t=a[i];
- }
- if (s==-1)
- printf("X ");
- else
- printf("%d ", s);
- if (t==-1)
- printf("X\n");
- else
- printf("%d\n", t);
- }
- return 0;
- }
Add Comment
Please, Sign In to add comment