-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathClimbingTheLeaderboard.cpp
More file actions
72 lines (50 loc) · 1.13 KB
/
ClimbingTheLeaderboard.cpp
File metadata and controls
72 lines (50 loc) · 1.13 KB
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
// problem: "https://www.hackerrank.com/challenges/climbing-the-leaderboard/problem"
#include<iostream>
using namespace std;
int main()
{
long long int i,j,LB[200010],R[200010],alice[200010],aliceR[200010],k,t,n,m;
cin>>n;
for(i=1;i<n+1;i++)
cin>>LB[i];
LB[0]=-1;
k=0;
for(i=1;i<n+1;i++)
{
if(LB[i]!=LB[i-1])
k++;
R[i]=k;
}
//for(i=1;i<n+1;i++)
//cout<<R[i]<<" ";
//cout<<endl;
cin>>m;
for(i=1;i<m+1;i++)
cin>>alice[i];
t=n;
for(i=1;i<m+1;i++)
{
for(j=t;j>0;j--)
{
if(alice[i]<LB[j])
{
aliceR[i]=R[j]+1;
t=j;
break;
}
else if(alice[i]==LB[j])
{
aliceR[i]=R[j];
t=j;
break;
}
if(j==1)
{
aliceR[i]=1;
}
}
}
for(i=1;i<m+1;i++)
cout<<aliceR[i]<<endl;
return 0;
}