Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Problem: G. Build an Array
- // Contest: Codeforces - Codeforces Round 1027 (Div. 3)
- // URL: https://codeforces.com/contest/2114/problem/G
- // Memory Limit: 512 MB
- // Time Limit: 1000 ms
- //
- // Powered by CP Editor (https://cpeditor.org)
- #include <assert.h>
- #include <bits/stdc++.h>
- using namespace std;
- #ifndef __DEBUG__
- #define dbg(...) 42
- #endif
- template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
- namespace rngs = std::ranges;
- using ll = long long;
- using a2l = array<ll, 2>;
- using pll = pair<ll, ll>;
- using vl = vector<ll>;
- void solve()
- {
- ll n, k;
- cin >> n >> k;
- vl a(n);
- for (auto &x : a)
- cin >> x;
- auto lowbit = [](ll x) { return x & -x; };
- vl pref(n), suff(n);
- // ll minv = n, maxv = lowbit(a.back());
- for (ll round = 0; round < 2; ++round) {
- auto &acc = round == 0 ? pref : suff;
- for (ll i = 0; i < n; ++i) {
- ll base = 0, delta = 0;
- if (i > 0) {
- base = acc[i - 1] - lowbit(a[i - 1]);
- ll x = a[i - 1], y = a[i];
- if (x % y == 0 && lowbit(x / y) == x / y) {
- // delta = max(1ll, x / y / 2);
- // delta = max(1ll, x / y - 1);
- delta = max(1ll, lowbit(x) - lowbit(y * 2) + 1);
- } else {
- delta = lowbit(x);
- }
- }
- // acc[i] = base + delta;
- acc[i] = base + lowbit(a[i]) + delta;
- }
- reverse(a.begin(), a.end());
- }
- rngs::reverse(suff);
- if (k < n) {
- cout << "NO\n";
- return;
- }
- dbg(pref, suff);
- for (ll i = 0; i < n; ++i) {
- ll val = pref[i] + suff[i] - lowbit(a[i]);
- dbg(val);
- if (val >= k) {
- cout << "YES\n";
- return;
- }
- }
- cout << "NO\n";
- }
- int main(int argc, char **argv)
- {
- std::ios::sync_with_stdio(false);
- std::cin.tie(nullptr);
- ll t;
- cin >> t;
- while (t--)
- solve();
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment