문제 링크: https://www.acmicpc.net/problem/12005
12005번: Diamond Collector (Bronze)
Bessie the cow, always a fan of shiny objects, has taken up a hobby of mining diamonds in her spare time! She has collected \(N\) diamonds (\(N \leq 1000\)) of varying sizes, and she wants to arrange some of them in a display case in the barn. Since Bessie
www.acmicpc.net
각각의 diamond를 제일 작은 size라고 취급하고, 같은 case 안에 들어갈수 있는 diamond 갯수를 세서, 최대값을 구함.
시간복잡도 O(N^2).
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
#include <bits/stdc++.h>
using namespace std;
int N, K, d[10001];
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cin >> N >> K;
for(int i = 0; i < N; i++) cin >> d[i];
int ans = 0;
for(int i = 0; i < N; i++) {
int cnt = 0;
for(int j = 0; j < N; j++) {
if(d[j] >= d[i] && d[j] - d[i] <= K)
cnt++;
}
ans = max(ans, cnt);
}
cout << ans << '\n';
return 0;
}
http://colorscripter.com/info#e" target="_blank" style="color:#4f4f4ftext-decoration:none">Colored by Color Scripter
|
'USACO > Bronze' 카테고리의 다른 글
백준 14174 Block Game (USACO December 2016 Bronze 2번) (0) | 2020.02.28 |
---|---|
백준 14173 Square Pasture (USACO December 2016 Bronze 1번) (0) | 2020.02.28 |
백준 12001 Load Balancing (USACO February 2016 Bronze 3번) (0) | 2020.02.27 |
백준 12000 Circular Barn (USACO February 2016 Bronze 2번) (0) | 2020.02.27 |
백준 11999 Milk Pails (USACO February 2016 Bronze 1번) (0) | 2020.02.27 |