fork download
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. void climbingLeaderboard(vector <int> scores, vector <int> alice) {
  6. vector <int> uniq(scores.size());
  7. vector <int> rank(scores.size()+1);
  8. int k=0,i,j;
  9. uniq[0]=scores[0];
  10. for(i=1;i<scores.size();i++)
  11. {
  12. if(scores[i]!=uniq[k])
  13. {
  14. k++;
  15. uniq[k]=scores[i];
  16.  
  17. }
  18. }
  19. for(i=0;i<alice.size();i++)
  20. {
  21. if(alice[i]>=uniq[0])
  22. rank[i]=1;
  23. else if(alice[i]<=uniq[k])
  24. rank[i]=k+2;
  25. else
  26. for(j=0;j<k;j++)
  27. {
  28. if(alice[i]<uniq[j]&&alice[i]>=uniq[j+1])
  29. rank[i]=j+2;
  30. }
  31. }
  32. for(i=0;i<alice.size();i++)
  33. cout<<rank[i]<<endl;
  34. }
  35.  
  36. int main() {
  37. int n;
  38. cin >> n;
  39. vector<int> scores(n);
  40. for(int scores_i = 0; scores_i < n; scores_i++){
  41. cin >> scores[scores_i];
  42. }
  43. int m;
  44. cin >> m;
  45. vector<int> alice(m);
  46. for(int alice_i = 0; alice_i < m; alice_i++){
  47. cin >> alice[alice_i];
  48. }
  49. climbingLeaderboard(scores, alice);
  50.  
  51. return 0;
  52. }
  53.  
Runtime error #stdin #stdout #stderr 0s 4424KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
terminate called after throwing an instance of 'std::bad_alloc'
  what():  std::bad_alloc