#include<bits/stdc++.h> #define int long long usingnamespace std; using ll = longlong; const ll mod = 7 + 1e9; ll gcd(ll a, ll b){ return b ? gcd(b, a % b) : a; }
voidsol() { ll n; cin >> n; ll ans = log2(n + 1); cout << ans << '\n'; } signedmain() { int t = 1; cin >> t; while (t--) sol(); return0; }
#include<bits/stdc++.h> usingnamespace std; using ll = longlong;
#define pii pair<int, int> constint N = 1010, mod = 998244353, INF = 0x3f3f3f3f;
char g[N][N]; int vis[N][N];
int dx[] = {-1, 1, 0, 0}; int dy[] = {0, 0, -1, 1}; voidsolve() { int n, m; cin >> n >> m; map<int, int> gx, gy; int sx, sy, ex, ey; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { cin >> g[i][j]; if (g[i][j] == 'S') sx = i, sy = j; if (g[i][j] == 'E') ex = i, ey = j; } } queue<pii> q, p; q.push({sx, sy});
while (!q.empty()) { auto [x, y] = q.front(); q.pop(); if (vis[x][y]) continue; vis[x][y] = 1; for (int i = -1; i <= 1; i++) { gx[x + i] = gy[y + i] = 1; } for (int i = 0; i < 4; i++) { int u = x + dx[i], v = y + dy[i]; if (u < 0 || v < 0 || u == n || v == m || g[u][v] == '#' || vis[u][v]) continue; q.push({u, v}); } } p.push({ex, ey});
while (!p.empty()) { auto [x, y] = p.front(); p.pop(); // cout << x << " " << y << endl; if (gx[x] || gy[y]) { cout << "YES\n"; return; } if (vis[x][y]) continue; vis[x][y] = 1;
for (int i = 0; i < 4; i++) { int u = x + dx[i], v = y + dy[i]; if (u < 0 || v < 0 || u == n || v == m || g[u][v] == '#' || vis[u][v]) continue; p.push({u, v}); } } cout << "NO\n"; } signedmain() { ios::sync_with_stdio(0), cin.tie(0); cout.tie(0); int T = 1; // cin >> T; while (T--) solve();
voidsolve() { ll n, m; cin >> n >> m; vector<pair<ll, ll>> vp(n); for (ll i = 0; i < n; i++) cin >> vp[i].first; for (ll i = 0; i < n; i++) cin >> vp[i].second; for (ll i = 0; i < n; i++) swap(vp[i].first, vp[i].second); sort(vp.begin(), vp.end()); vector<ll> k; ll p = 0; while (p < n) { ll rp = vp[p].first + vp[p].second; ll sz = 1; while (p + 1 < n && rp >= vp[p + 1].first) { p++; sz++; rp = max(rp, vp[p].first + vp[p].second); } p++; k.push_back(sz); } sort(k.begin(), k.end()); reverse(k.begin(), k.end()); ll ans = 0; for (ll i = 0; i < k.size() && i < m; i++) { ans += k[i]; } cout << ans << endl; }