Plabon_dutta

Codeforces Round #735 (Div. 2), problem: (B) Cobb

Jul 29th, 2021 (edited)
1,017
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define pi acos(-1.0)
  6. #define ll long long int
  7. #define sc scanf
  8. #define pf printf
  9. #define fin for(ll i=0; i<n; i++)
  10. #define fjm for(ll j=0; j<m; j++)
  11. #define fr(i,a,n) for(ll i=a; i<n; i++)
  12. #define rf(i,n,a) for(ll i=n-1; i>=a; i--)
  13. #define pb push_back
  14. #define nl "\n"
  15. #define readfirst() (ios_base:: sync_with_stdio(false),cin.tie(NULL));
  16.  
  17. ll gcd(ll p, ll q) {
  18.     return q==0?p:gcd(q,p%q);
  19. }
  20.  
  21. int main() {
  22.     readfirst();
  23.     ll t, k;
  24.     int n;
  25.     cin >> t;
  26.     while(t--) {
  27.         cin >> n >> k;
  28.         ll a[n+2], x, c=0;
  29.         fin cin >> a[i];
  30.         for(ll i=n; i>=max(0,n-200); i--) {
  31.             for(ll j=i-1; j>=max(0,n-200); j--) {
  32.                 if(c==0) {
  33.                     x=((i+1)*(j+1)-k*(a[i]|a[j]));
  34.                     c=1;
  35.                 }
  36.                 else x=max(x, (i+1)*(j+1)-k*(a[i]|a[j]));
  37.             }
  38.         }
  39.         cout << x << nl;
  40.     }
  41.     return 0;
  42. }
RAW Paste Data