2790 F7
2019. 10. 6. 01:13ㆍ알고리즘/백준
먼저 점수를 모두 입력받은 후 정렬한다. 맨 앞 최고점수를 기준으로 아래로 내려간다. 초반에 최고점수는 맨 앞의 점수+1이 된다. 왜냐하면 가능성을 추적하는 것이기 때문에 제일 낮은 점수를 할당한다. 그리고 다음과 같은 로직으로 내려간다
if ( 최고점수 <= 점수 + N ) {
ans += 1;
최고점수 = max(최고점수, 점수 + 인덱스)
}
else break
문제: https://www.acmicpc.net/problem/2790
깃허브주소: https://github.com/surinoel/boj/blob/master/2790.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <vector> | |
#include <iostream> | |
#include <algorithm> | |
#include <functional> | |
using namespace std; | |
int main(void) { | |
ios_base::sync_with_stdio(false); | |
cin.tie(nullptr); | |
int n; | |
cin >> n; | |
vector<int> v(n); | |
for (int i = 0; i < n; i++) { | |
cin >> v[i]; | |
} | |
sort(v.begin(), v.end(), greater<int>()); | |
int maxv = v[0] + 1; | |
int ans = 1; | |
for (int i = 1; i < v.size(); i++) { | |
if (maxv > v[i] + n) { | |
break; | |
} | |
maxv = max(maxv, v[i] + i + 1); | |
ans += 1; | |
} | |
cout << ans << '\n'; | |
return 0; | |
} |
'알고리즘 > 백준' 카테고리의 다른 글
17487 타자 연습 (0) | 2019.10.07 |
---|---|
17472 다리 만들기 2 (0) | 2019.10.07 |
프로그래머스 모의고사 (0) | 2019.10.04 |
10250 ACM 호텔 (0) | 2019.10.03 |
16935 배열 돌리기 3 (0) | 2019.10.02 |