-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathClimbing the Leaderboard.cpp
77 lines (55 loc) · 955 Bytes
/
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/*
problem link:https://www.hackerrank.com/challenges/climbing-the-leaderboard/problem
problem name:Climbing the Leaderboard
status :accepted
author :mohand sakr..
*/
#include<vector>
#include <algorithm>
#include<map>
#include <iostream>
using namespace std;
int n;
vector<int> board;
map<int,int> refrence;
int m;
int main() {
cin>>n;
for(int i=0;i<n;i++){
int x;
cin>>x;
board.push_back(x);
}
sort(board.begin(),board.end());
reverse(board.begin(),board.end());
int currentscore=0;
for(int i=0;i<n;i++){
if(!refrence[board[i]])
{
refrence[board[i]]=++currentscore;
}
}
sort(board.begin(),board.end());
cin>>m;
vector<int>::iterator lower;
for(int i=0;i<m;i++)
{
int x;
cin>>x;
lower=lower_bound(board.begin(),board.end(),x);
int value=*lower;
if(value){
if(x==value){
cout<<refrence[x]<<endl;
}
else
{
cout<<refrence[value]+1<<endl;
}
}
else {
cout<<1<<endl;
}
}
return 0;
}