fork(15) download
  1. #include <bits/stdc++.h>
  2. #define msg(x) cout << #x << " = " << x << endl
  3. using namespace std;
  4.  
  5. int n, x;
  6. multiset<int> s;
  7. multiset<int>::iterator it;
  8.  
  9. int main() {
  10. cin.sync_with_stdio(0); cin.tie(0);
  11. cin >> n;
  12. for (int i = 0; i < n; i++) {
  13. cin >> x;
  14. if (x - i > 0) {
  15. //this part is fastest way (code-wise) i know of finding
  16. //longest non-decreasing subsequence
  17. //if you simply want longest increasing, replace multiset with set
  18. x -= i;
  19. s.insert(x);
  20. it = upper_bound(s.begin(), s.end(), x);
  21. if (it != s.end()) s.erase(it);
  22. }
  23. }
  24. cout << n - s.size() << endl;
  25. return 0;
  26. }
  27.  
Success #stdin #stdout 0s 3432KB
stdin
Standard input is empty
stdout
0