-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPizzamania.cpp
More file actions
38 lines (36 loc) · 830 Bytes
/
Pizzamania.cpp
File metadata and controls
38 lines (36 loc) · 830 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
/** https://www.spoj.com/problems/OPCPIZZA/
* #binary-search
*/
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main() {
int t, n, m;
cin >> t;
for(int i=0; i < t; i++) {
cin >> n;
cin >> m;
vector<int> arr(n);
int tmp;
for(int k=0; k < n; k++) {
cin >> tmp;
arr[k] = tmp;
}
sort(arr.begin(), arr.end());
int count = 0;
int left = 0, right = n-1;
while (left < right) {
if (arr[left] + arr[right] == m) {
count++;
right--;
left++;
} else if (arr[left] + arr[right] > m) {
right--;
} else {
left++;
}
}
cout << count << endl;
}
}