Competition/codeforces
Educational Codeforces Round 62 (Rated for Div. 2) A. Detective Book
shyram
2019. 4. 1. 18:05
A. Detective Book
https://codeforces.com/contest/1140/problem/A
하루에 마주치는 모든 i번째 배열의 값 중 최대값에 해당하는 인덱스에 도달할 때까지 책을 읽어야 한다.
따라서 max값을 계속 갱신하다가, 그 max값이 가리키고 있는 인덱스에 도달하면 할당량에 도달한 것이다.
그러면 day를 하나씩 더해주자.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | #include <bits/stdc++.h> using namespace std; int n; int arr[10001]; int main() { ios::sync_with_stdio(0); cin.tie(NULL); cin >> n; for (int i = 1; i <= n; i++) cin >> arr[i]; int day = 0; int maxread = 1; for (int i = 1; i <= n; i++) { maxread = max(arr[i], maxread); if (maxread == i) { day++; } } cout << day; } | cs |