8000 Merge pull request #465 from syoh0708/0x14_20366 · kwon5346/basic-algo-lecture@bfb4486 · GitHub
[go: up one dir, main page]

Skip to content

Commit bfb4486

Browse files
Merge pull request encrypted-def#465 from syoh0708/0x14_20366
Create 20366.cpp
2 parents ca87dc3 + 1b894ee commit bfb4486

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

0x14/solutions/20366.cpp

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,41 @@
1-
// Authored by : BaaaaaaaaaaarkingDog
1+
// Authored by : syoh0708
22
// Co-authored by : -
3-
// http://boj.kr/****************
3+
// http://boj.kr/3589e6590845469191b7873b71550403
44
#include <bits/stdc++.h>
5+
56
using namespace std;
67

7-
int main(void){
8+
const int MAX = 1'000'000'000;
9+
int n, ans = MAX;
10+
int a[605];
11+
12+
int main() {
813
ios::sync_with_stdio(0);
914
cin.tie(0);
10-
11-
}
15+
16+
cin >> n;
17+
18+
for (int i = 0; i < n; i++) cin >> a[i];
19+
20+
sort(a, a + n);
21+
22+
for (int i1 = 0; i1 < n; i1++) {
23+
for (int i2 = i1 + 3; i2 < n; i2++) {
24+
int j1 = i1 + 1, j2 = i2 - 1;
25+
26+
while (j1 < j2) {
27+
ans = min(ans, abs(a[i1] + a[i2] - a[j1] - a[j2]));
28+
29+
if (a[i1] + a[i2] <= a[j1] + a[j2]) j2--;
30+
else j1++;
31+
}
32+
}
33+
}
34+
35+
cout << ans;
36+
}
37+
/*
38+
답을 구성하는 눈사람이 a,b,c,d(a <= b <= c <= d)라고 할 때 (a, d)가 한 묶음이고
39+
(b, c)가 한 묶음인건 자명하기 때문에 인덱스를 i1 < j1 < j2 < i2로 둘 수 있다.
40+
a[i1]+a[i2]와 a[j1]+a[j2]가 근접한 (j1, j2) 쌍을 구하면 된다.
41+
*/

0 commit comments

Comments
 (0)
0