fork download
  1. #include <iostream>
  2. #include <vector>
  3.  
  4. using namespace std;
  5.  
  6. int main() {
  7. int n;
  8. cin >> n;
  9.  
  10. vector<int> diff(n - 1);
  11. for (int i = 0; i < n - 1; ++i) {
  12. cin >> diff[i];
  13. }
  14.  
  15. vector<int> result(n);
  16. for (int i = 0; i < n; ++i) {
  17. int rank = 1;
  18. for (int j = i - 1; j >= 0; --j) {
  19. if (diff[j] >= rank) {
  20. ++rank;
  21. }
  22. }
  23. result[i] = rank;
  24. }
  25.  
  26. int q;
  27. cin >> q;
  28. for (int i = 0; i < q; ++i) {
  29. int pos;
  30. cin >> pos;
  31. cout << result[pos - 1] << endl;
  32. }
  33.  
  34. return 0;
  35. }
  36.  
Success #stdin #stdout 0.01s 5304KB
stdin
7
1 0 3 0 2 3
4
7
2
5
1
stdout
4
2
2
1