-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClimbing_the_Leaderboard.cpp
52 lines (49 loc) · 1.18 KB
/
Climbing_the_Leaderboard.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include <bits/stdc++.h>
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#define f(i,a,b) for(i=a;i<b;i++)
#define fr(i,a,b) for(i=a;i>=b;i--)
#define sp "\t"
#define ll long long int
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define mod 1000000007
using namespace std;
main()
{
vector<int> s;
vector<int> a;
int i,n,na;
cin>>n;
f(i,0,n)
{
int p;
cin>>p;
s.push_back(p);
}
vector<int>::iterator ip;
ip=std::unique(s.begin(),s.end()); //removes the duplicate
s.resize(std::distance(s.begin(),ip)); //resizes the vector
n=s.size();
cin>>na;
f(i,0,na)
{
int p;
cin>>p;
a.push_back(p);
}
for(auto y:a)
{
int flag=0;
fr(i,n-1,0)
{
if(flag==0)
{
if(y>s[i] && y<s[i-1]) {cout<<i+1<<" ";flag=1;}
else if(y>s[i]) {cout<<i+1;flag=1;}
if(s[i]>y) {cout<<i+2<<" ";flag=1;}
}
}
}
}