a53

Exclusiv

a53
Apr 20th, 2021
170
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.45 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4. ifstream fin("exclusiv.in");
  5. ofstream fout("exclusiv.out");
  6. struct elem
  7. {
  8. int val, ind;
  9. };
  10. elem v[2005];
  11. int N, M, s[100005], sol[2005];
  12. int maxm, l, lmax;
  13. bool compara(elem a, elem b)
  14. {
  15. if(a.val != b.val)
  16. return (a.val < b.val);
  17. return (a.ind < b.ind);
  18. }
  19. int cautB(elem sir[], int n, int x)
  20. {
  21. int low=1, high=n, res = -1;
  22. while(low <= high)
  23. {
  24. int mid = (low + high) / 2;
  25. if(sir[mid].val > x)
  26. high = mid - 1;
  27. else if(sir[mid].val < x)
  28. low = mid + 1;
  29. else
  30. {
  31. res=mid;
  32. high=mid-1;
  33. }
  34. }
  35. return res;
  36. }
  37. int main()
  38. {
  39. int i, j;
  40. fin>>M>>N;
  41. for(i=1; i<=M; ++i)
  42. fin>>s[i];
  43. for(i=1; i<=N; ++i)
  44. {
  45. fin>>v[i].val;
  46. v[i].ind=i;
  47. }
  48. sort(v+1, v+N+1, compara);
  49. for(j=1; j<=M; ++j)
  50. {
  51. int cb=cautB(v, N, s[j]);
  52. if(cb>0)
  53. s[j]=v[cb].ind;
  54. else
  55. s[j]=(N+1);
  56. }
  57. for(i=1; i<=N; ++i)
  58. {
  59. int lg=0;
  60. for(j=1; j<=M; ++j)
  61. {
  62. if(s[j]>i)
  63. {
  64. lg++;
  65. }
  66. else
  67. {
  68. sol[i]=max(lg, sol[i]);
  69. lg=0;
  70. }
  71. }
  72. sol[i]=max(lg, sol[i]);
  73. }
  74. for(i=1; i<=N; ++i)
  75. fout<<sol[i]<<'\n';
  76. return 0;
  77. }
Advertisement
Add Comment
Please, Sign In to add comment