#include using namespace std; uint32_t getCost(const vector&vec, const uint32_t &l, const uint32_t &r) { uint32_t retVal = 0, maxVal = 0, minVal = 0xFFFFFFFF, ORVal = 0, ANDVal = 0xFFFFFFFF; for (uint32_t i = l; i <= r; i++) { if (maxVal < vec[i]) maxVal = vec[i]; if (minVal > vec[i]) minVal = vec[i]; ORVal |= vec[i]; ANDVal &= vec[i]; } retVal = (ORVal - ANDVal) - (maxVal - minVal); return retVal; } vector costlyIntervals(uint32_t n, uint32_t k, vector A) { // Return a list of length n consisting of the answers // Initialize vector of return values to -1 vector sol(n); for (auto &X : sol) X = -1; for (uint32_t i = 0; i < n; i++) { uint32_t costTillNow = 0; uint32_t retVal = 0, maxVal = 0, minVal = 0xFFFFFFFF, ORVal = 0, ANDVal = 0xFFFFFFFF; for (uint32_t j = i; j < n; j++) { if (maxVal < A[j]) maxVal = A[j]; if (minVal > A[j]) minVal = A[j]; ORVal |= A[j]; ANDVal &= A[j]; costTillNow = (ORVal - ANDVal) - (maxVal - minVal); //cout<<"Cost "<= k) for (uint32_t k = i; k <=j; k++) if (sol[k] < (int32_t)(j-i+1)) sol[k] = (j-i+1); } } return sol; } int main() { uint32_t n; uint32_t k; cin >> n >> k; vector A(n); for(int A_i = 0; A_i < n; A_i++){ cin >> A[A_i]; } vector result = costlyIntervals(n, k, A); for (ssize_t i = 0; i < result.size(); i++) { cout << result[i] << (i != result.size() - 1 ? "\n" : ""); } cout << endl; return 0; }