-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path3273.cpp
More file actions
51 lines (45 loc) · 740 Bytes
/
3273.cpp
File metadata and controls
51 lines (45 loc) · 740 Bytes
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
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// 3273. 두 수의 합
// 2021.10.03
// 정렬
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main()
{
int n, x;
int ans = 0;
cin >> n;
vector<int> v(n);
for (int i = 0; i < n; i++)
{
cin >> v[i];
}
sort(v.begin(), v.end());
cin >> x;
int start = 0;
int end = n - 1;
while (1)
{
if (start >= end)
{
break;
}
if (v[start] + v[end] == x)
{
start++;
end--;
ans++;
}
else if (v[start] + v[end] > x)
{
end--;
}
else
{
start++;
}
}
cout << ans << endl;
return 0;
}