|Ai + T - Bi| 의 최솟값!
여러 값이 있을 때 홀수면 중간값 짝수면 중간에 있는 두 값의 사이값들이 최소이다.
수학으로 해결
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <functional>
#include <string>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cmath>
#include <cstring>
#include <bitset>
#include <stdio.h>
#include <math.h>
#include <sstream>
#define xx first
#define yy second
#define all(x) (x).begin(), (x).end()
using namespace std;
using i64 = long long int;
using ii = pair<int, int>;
using iis = pair<int, string>;
using ii64 = pair<i64, i64>;
using iii = tuple<int, int, int>;
int main() {
int n;
scanf("%d", &n);
if (n % 2 == 1) {
printf("1");
return 0;
}
vector<i64> v(n);
for (int i = 0; i < n; i++) {
int a, b;
scanf("%d %d", &a, &b);
v[i] = (a - b) * -1;
}
sort(all(v));
printf("%d", abs(v[n/2] - v[n/2 - 1]) + 1);
return 0;
}
'백준' 카테고리의 다른 글
18788 Swapity Swap (0) | 2022.05.22 |
---|---|
16654 Generalized German Quotation (0) | 2022.05.21 |
10487 4 thought (0) | 2022.05.14 |
19952 인성 문제 있어?? (0) | 2022.05.14 |
1013 Contact (0) | 2022.05.08 |