# Link
https://www.acmicpc.net/problem/1337
1337번: 올바른 배열
첫째 줄에 배열의 크기 N이 주어진다. N은 50보다 작거나 같은 자연수이다. 둘째 줄부터 N개의 줄에 배열의 원소가 한 줄에 하나씩 주어진다. 원소는 1,000,000,000보다 작거나 같은 음이 아닌 정수이
www.acmicpc.net
# Code - C++
//
// BOJ
// ver.C++
//
// Created by GGlifer
//
// Open Source
#include <iostream>
#include <algorithm>
using namespace std;
#define endl '\n'
#define len(x) (int)(x).length()
#define size(x) (int)(x).size()
#define str(x) to_string(x)
#define error logic_error("line " + str(__LINE__))
// Set up : Definitions
/* None */
// Set up : Global Variables
/* None */
// Set up : Functions Declaration
/* None */
int main()
{
// Set up : I/O
ios::sync_with_stdio(false);
cin.tie(nullptr);
// Set up : Input
int N; cin >> N;
int A[N];
for (int i=0; i<N; i++)
cin >> A[i];
// Process
sort(A, A+N);
int ans = 4;
for (int i=0; i<N; i++) {
int tmp = distance(A+i, lower_bound(A, A+N, A[i]+5));
ans = min(ans, 5-tmp);
}
// Control : Output
cout << ans << endl;
}
// Helper Functions
/* None */
지적, 조언, 첨언 모두 환영합니다!!!
'Problem Solving > 백준' 카테고리의 다른 글
| [ Problem Solving :: 백준 ] 10699 / 오늘 날짜 (0) | 2021.11.15 |
|---|---|
| [ Problem Solving :: 백준 ] 11657 / 타임머신 (0) | 2021.11.15 |
| [ Problem Solving :: 백준 ] 8983 / 사냥꾼 (0) | 2021.11.13 |
| [ Problem Solving :: 백준 ] 2075 / N번째 큰 수 (0) | 2021.11.12 |
| [ Problem Solving :: 백준 ] 2840 / 행운의 바퀴 (0) | 2021.11.05 |