-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathB_Cobb.cpp
More file actions
56 lines (52 loc) · 1.03 KB
/
B_Cobb.cpp
File metadata and controls
56 lines (52 loc) · 1.03 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
52
53
54
55
56
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll k;
bool comp(pair<ll, ll> p1, pair<ll, ll> p2)
{
ll x = p1.first - k * p1.second;
ll y = p2.first - k * p2.second;
return x > y;
}
void solve(ll n)
{
cin >> k;
vector<pair<ll, ll>> v;
for (int i = 0; i < n; i++)
{
ll x;
cin >> x;
v.push_back(make_pair(i + 1, x));
}
sort(v.begin(), v.end(), comp);
ll ans = INT_MIN;
for (int i = 0; i < min((ll)100, n - 1); i++)
{
for (int j = i + 1; j < n; j++)
{
ll curr = (v[i].first) * (v[j].first) - k * (v[i].second | v[j].second);
if (curr > ans)
{
ans = curr;
}
}
}
cout << ans << endl;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
ll t;
cin >> t;
while (t--)
{
// string str; //for reading empty line
// getline(cin, str);
ll n;
cin >> n;
solve(n);
}
return 0;
}