My issue
for some cases it is a tle problem, and for the input case
1
7
1 3 8 7 10 4 2
expected output is
11
11
12
10
10
10
9
10
11
10
4
10
11
11
11
9
11
10
12
10
10
10
10
10
10
10
9
3
11
10
5
11
7
11
10
11
12
7
10
10
10
10
6
10
10
10
10
12
9
4
while my output is
4
which i believe is logically the correct output too.
where am i going wrong?
My code
#include <iostream>
using namespace std;
int main() {
int t; cin>>t ;
while(t--){
int n; cin>>n ;
int array[n];
for(int k = 0; k<n; k++){
cin>>array[k];
}
int start = array[0] ;
int end = array[0] ;
int ans = 2 ;
if(n<=1){
cout<<"1"<<endl ;
}
for(int i =0; i<n-1 ; i++){
end = max(end, array[i] +i) ;
if(i == start){
ans++ ;
start = end ;
}
}
cout<<ans<<endl ;
}
return 0;
}
Problem Link: CodeChef: Practical coding for everyone