1 条题解
-
0
维护一个最大值 ,表示在每个站点能走到的最远位置。
遍历数组,对于每个点,先判断当前能走到的最远距离是否能到达当前点,再更新 。
#include<bits/stdc++.h> using namespace std; typedef long long LL; typedef pair<LL, LL> PII; #define x first #define y second const int N = 2e5 + 10, M = 60; int a[N]; void solve() { int n; cin >> n; for(int i = 1; i <= n; i ++) { cin >> a[i]; } int ma = 1; for(int i = 1; i <= n; i ++) { if(i > ma) { cout << "NO\n"; return; } ma = max(ma, i + a[i]); } cout << "YES\n"; } int main() { int t = 1; // cin >> t; while(t --) solve(); }
- 1
信息
- ID
- 439
- 时间
- 1000ms
- 内存
- 256MiB
- 难度
- 9
- 标签
- 递交数
- 18
- 已通过
- 2
- 上传者