#include <iostream>
#include <algorithm>
using namespace std;
static const auto fastio = []() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
cout.tie(nullptr);
return 0;
};
int n, m, s[15151], cnt;
int main() {
cin >> n >> m;
for (int i = 0; i < n; i++) cin >> s[i];
sort(s, s + n);
int l = 0, r = n - 1;
while (l < r) {
if (s[l] + s[r] == m) {
l++;
r--;
cnt++;
}
else if (m < s[l] + s[r]) {
r--;
}
else {
l++;
}
}
cout << cnt;
return 0;
}
|
cs |
간단한 투 포인터 문제 입니다.
'설명없음' 카테고리의 다른 글
백준 16236: 아기 상어 [C언어], 삼성 코딩 테스트 (0) | 2022.06.13 |
---|---|
백준 14921: 용액 합성하기 [C/C++] (0) | 2022.06.08 |
백준 1484: 다이어트 [C/C++] (0) | 2022.06.08 |
백준 20192: 순서 섞기 [C언어] (0) | 2022.06.03 |
백준 11053: 가장 긴 증가하는 부분 수열, 파이썬 (0) | 2022.06.03 |