forked from rohitthapliyal2000/Competitive-Algorithms
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboats.cpp
More file actions
51 lines (47 loc) · 1.01 KB
/
boats.cpp
File metadata and controls
51 lines (47 loc) · 1.01 KB
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
#include <bits/stdc++.h>
#define fastio \
ios_base::sync_with_stdio(false); \
cin.tie(NULL)
#define endl "\n"
using namespace std;
int main()
{
fastio;
int t;
cin >> t;
map<int, int> mape;
while(t--)
{
int n, max = -1;
cin >> n;
vector<int> a;
for(int i = 0; i < n; i++)
{
cin >> max;
a.push_back(max);
}
max = -1;
sort(a.begin(), a.end());
for(int i = 2; i <= 100; i++)
{
int x = 0, y = n-1, count = 0;
while(x < y)
{
if(a[x] + a[y] == i)
{
x++;
y--;
count++;
}
else if(a[x] + a[y] > i)
y--;
else if(a[x] + a[y] < i)
x++;
}
if(count > max)
max = count;
}
cout << max << "\n";
}
return 0;
}