Skip to content

Commit

Permalink
Merge pull request #465 from syoh0708/0x14_20366
Browse files Browse the repository at this point in the history
Create 20366.cpp
  • Loading branch information
encrypted-def authored Jan 18, 2024
2 parents ca87dc3 + 1b894ee commit bfb4486
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions 0x14/solutions/20366.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,41 @@
// Authored by : BaaaaaaaaaaarkingDog
// Authored by : syoh0708
// Co-authored by : -
// http://boj.kr/****************
// http://boj.kr/3589e6590845469191b7873b71550403
#include <bits/stdc++.h>

using namespace std;

int main(void){
const int MAX = 1'000'000'000;
int n, ans = MAX;
int a[605];

int main() {
ios::sync_with_stdio(0);
cin.tie(0);

}

cin >> n;

for (int i = 0; i < n; i++) cin >> a[i];

sort(a, a + n);

for (int i1 = 0; i1 < n; i1++) {
for (int i2 = i1 + 3; i2 < n; i2++) {
int j1 = i1 + 1, j2 = i2 - 1;

while (j1 < j2) {
ans = min(ans, abs(a[i1] + a[i2] - a[j1] - a[j2]));

if (a[i1] + a[i2] <= a[j1] + a[j2]) j2--;
else j1++;
}
}
}

cout << ans;
}
/*
답을 구성하는 눈사람이 a,b,c,d(a <= b <= c <= d)라고 할 때 (a, d)가 한 묶음이고
(b, c)가 한 묶음인건 자명하기 때문에 인덱스를 i1 < j1 < j2 < i2로 둘 수 있다.
a[i1]+a[i2]와 a[j1]+a[j2]가 근접한 (j1, j2) 쌍을 구하면 된다.
*/

0 comments on commit bfb4486

Please sign in to comment.