- 문제 링크 : boj.kr/31235
- 난이도 : G4
- 태그 : 그리디
코드
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
#define INF 0x7FFFFFFF
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int,int>;
using pll = pair<ll, ll>;
int main()
{
ios::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int n;
cin >> n;
vector<int> arr(n);
for(auto &u : arr) cin >> u;
int cnt = 0;
int ans = 0;
int before = arr[0];
for(int i = 1; i < n; i++) {
if(arr[i] < before) {
cnt++;
}
else {
before = arr[i];
cnt = 0;
}
ans = max(ans, cnt);
}
cout << ans + 1;
return 0;
}
풀이
만약 a_i > a_j (i < j) 일때 j-i < k-1라면 조건을 만족할 수 없다.
따라서 가능한 ij쌍에 대해 확인하면 된다.
단, i < x < j일때 a_i > a_x고, a_i < a_j라면, a_x < a_j인 것은 당연하다. 따라서 O(N)으로 확인할 수 있다.
728x90
'PS' 카테고리의 다른 글
BOJ 1374 : 강의실 (0) | 2024.06.27 |
---|---|
BOJ 10975 : 데크 소트 2 (0) | 2024.06.26 |
BOJ 12931 : 두 배 더하기 (0) | 2024.06.24 |
BOJ 2668 : 숫자고르기 (0) | 2024.06.23 |
BOJ 1689 : 겹치는 선분 (0) | 2024.06.22 |