Last active
April 5, 2018 12:45
-
-
Save satylogin/082f94be41e4705def537f78ed3af516 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <bits/stdc++.h> | |
using namespace std; | |
#define MOD 1000000007 | |
#define ll long long int | |
#define ld long double | |
#define pb push_back | |
#define mkp make_pair | |
#define pii pair<int, int> | |
#define pll pair<long long int, long long int> | |
#define sci(x) scanf("%d", &x) | |
#define scl(x) scanf("%lld", &x) | |
#define fi first | |
#define sc second | |
#define eps 1e-9 | |
int A[200001]; | |
int main() | |
{ | |
ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0); | |
int n, q, i, j, k, x, y, z; | |
cin >> n >> q; | |
for (i = 0; i < n; ++i) cin >> A[i]; | |
while (q--) { | |
cin >> k; | |
int ans = MOD; | |
int j = 0; | |
int cur = 0; | |
for (int i = 0; i < n; ++i) { | |
cur += __builtin_popcount(A[i]); | |
while (cur >= k && j < n) { | |
ans = min(ans, i-j+1); | |
cur -= __builtin_popcount(A[j++]); | |
} | |
} | |
if (k == 0) ans = 1; | |
if (ans == MOD) ans = -1; | |
cout << ans << endl; | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment