提交时间:2024-04-14 14:47:13
运行 ID: 28364
#include<iostream> using namespace std; const int maxn = 1e5 + 15; int a[maxn]; int main(){ int n, cnt = 0; cin >> n; int l = 1, f = 1; for(int i = 1, m;i <= n;i++){ cin >> m; if(i > l) a[cnt++] = f; if(i + m > l){ l = i + m; f = i; } } if(l < n + 1){ a[cnt++] = f; } cout << cnt << endl; for(int i = 0;i < cnt;i++){ cout << a[i] << " "; } return 0; } //5 4 3 3 2 1 0 0 0 1 0 0 //