fork download
  1. #include<iostream>
  2. #include<algorithm>
  3. #include<vector>
  4. #include<map>
  5. #include<cmath>
  6. #include<cstring>
  7. #include<set>
  8. #include<queue>
  9. #include<deque>
  10. #include<stack>
  11. #include<string>
  12. using namespace std;
  13. int n, m, pilot[100010], max_, ans, cc;
  14. int main() {
  15. ios_base::sync_with_stdio(false);
  16. cin.tie(NULL);
  17.  
  18. cin >> n >> m;
  19. for (int i = 1; i <= m; i++) {
  20. int a;
  21. cin >> a;
  22. if (cc == false) {
  23. if (max_ < a) {
  24. max_ = a;
  25. }
  26. pilot[a]++;
  27. if (max_ < i || pilot[a] > a) {
  28. ans = i - 1;
  29. cc = true;
  30. }
  31. else {
  32. ans = i;
  33. }
  34. }
  35. }
  36. cout << ans;
  37. return 0;
  38. }
Success #stdin #stdout 0.01s 5280KB
stdin
4
4
4
2
2
1
stdout
4