fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. typedef vector<int> vi;
  5. typedef pair <int, int> ii;
  6. typedef pair <ll, int> li;
  7. #define mk make_pair
  8.  
  9. const int N = 5e5 + 5;
  10.  
  11. int n;
  12. int a[N];
  13.  
  14. bool cmp(const int& a, const int& b)
  15. {
  16. return abs(a) < abs(b);
  17. }
  18.  
  19. bool cc(int a, int b)
  20. {
  21. if (a >= 0 && b < 0) return true;
  22. if (a < 0 && b >= 0) return true;
  23. return false;
  24. }
  25.  
  26. vector<int> dp;
  27.  
  28.  
  29. int main()
  30. {
  31. ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
  32.  
  33. #define file "XAYTHAP"
  34. freopen(file".INP", "r", stdin);
  35. freopen(file".OUT", "w", stdout);
  36.  
  37. cin >> n;
  38.  
  39. for (int i = 1; i <= n; i++) cin >> a[i];
  40.  
  41. sort(a + 1, a + n + 1, cmp);
  42.  
  43. for (int i = 1; i <= n; i++)
  44. {
  45. if (dp.empty() || (abs(dp.back()) < abs(a[i]) && cc(dp.back(), a[i])))
  46. {
  47. dp.push_back(a[i]);
  48. }
  49. }
  50.  
  51. cout << dp.size();
  52.  
  53.  
  54.  
  55. return 0;
  56. }
Success #stdin #stdout 0.01s 5288KB
stdin
Standard input is empty
stdout
Standard output is empty