a53

MordorTrip

a53
Jul 31st, 2021
139
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. ifstream fin("mordortrip.in");
  4. ofstream fout("mordortrip.out");
  5. int main() {
  6.  
  7. //citirea inputului.
  8. long long n;
  9. fin >> n;
  10. vector<int> a(n + 1);
  11. for (int i = 1; i <= n; ++i) {
  12. fin >> a[i];
  13. }
  14.  
  15. //sortarea vectorului auxiliar.
  16. vector<int> b = a;
  17. sort(b.begin() + 1, b.end(), greater<int>());
  18. long long ans = 0;
  19. for (long long i = 1; i <= n; ++i) {
  20.  
  21. //caut binar pozitia in vectorul sortat elemntului i.
  22. int st = 1, dr = n;
  23. int rep = 0;
  24. while (st <= dr) {
  25. int mid = (st + dr) / 2;
  26. if (b[mid] >= a[i]) {
  27. st = mid + 1;
  28. rep = mid;
  29. }
  30. else {
  31. dr = mid - 1;
  32. }
  33. }
  34. //updatez raspunsul.
  35. ans = max(ans, i - rep);
  36. }
  37. fout << ans;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment