voidsolve(){ int _; cin >> _; for (int ts = 0; ts < _; ++ts) { int n, m; cin >> n >> m; vector<string> data(n); for (auto &item : data) item.reserve(m); for (auto &item : data) cin >> item;
string vika = "vika"; int cur = 0; for (int i = 0; i < m && cur < vika.size(); ++i) { for (int j = 0; j < n; ++j) { if (data[j][i] == vika[cur]) { cur++; break; } } } cout << (cur == vika.size() ? "YES" : "NO") << endl; } }
voidsolve(){ int _; cin >> _; for (int ts = 0; ts < _; ++ts) { int n, mid; cin >> n; mid = (int)sqrt(n * 2); int ans = LONG_LONG_MAX; for (int i = max(2LL, mid - 10); i < mid + 10; ++i) if (i * (i - 1) / 2 <= n) ans = min(ans, i + n - (i * (i - 1) / 2)); cout << ans << endl; } }
voidsolve(){ int _; cin >> _; for (int ts = 0; ts < _; ++ts) { int n, m, d; cin >> n >> m >> d; int ans = 0, cur = 0; priority_queue<int, vector<int>, greater<>> prq; for (int i = 0; i < n; ++i) { cur -= d; int tmp; cin >> tmp; if (tmp < 0) continue;
if (prq.size() < m) { prq.push(tmp); cur += tmp; } elseif (tmp > prq.top()) { cur -= prq.top(); cur += tmp; prq.pop(); prq.push(tmp); } ans = max(ans, cur); }
voidsolve(){ int _; cin >> _; for (int ts = 0; ts < _; ++ts) { int f, w; cin >> f >> w; int n, sum = 0; cin >> n; vector<int> data(n); for (int i = 0; i < n; ++i) cin >> data[i]; for (int i = 0; i < n; ++i) sum += data[i];
if (f >= sum || w >= sum) { cout << 1 << endl; continue; }
int p = (sum + f + w - 1) / (f + w), ans; { int target = f * p; vector<int> dp(target + 1); for (int i = 0; i < n; ++i) for (int j = target; j >= data[i]; --j) dp[j] = max(dp[j], dp[j - data[i]] + data[i]);
int maxDp = 0; for (int i = 0; i <= target; ++i) maxDp = max(maxDp, dp[i]); if (sum - maxDp <= p * w) ans = p; else ans = (sum - maxDp + w - 1) / w; dp.clear(); }
{ int target = w * p; vector<int> dp(target + 1); for (int i = 0; i < n; ++i) for (int j = target; j >= data[i]; --j) dp[j] = max(dp[j], dp[j - data[i]] + data[i]);
int maxDp = 0; for (int i = 0; i <= target; ++i) maxDp = max(maxDp, dp[i]); if (sum - maxDp <= p * f) ans = min(ans, p); else ans = min(ans, (sum - maxDp + f - 1) / f); dp.clear(); }
cout << ans << endl;
} }
G. The Great Equalizer
大致题意
每次,将数组排序后,为一个数组中的每个值加上 $n, n - 1, n - 2 \dots, 1$,然后去重,重复,直到只剩下一个值,问最后这个值是什么。
map<int, int> dif, cnt; for (int i = 0; i < n; ++i) cnt[data[i]]++; for (int i = 1; i < n; ++i) dif[copy[i] - copy[i - 1]]++;
int total = 0; for (int i = 1; i < n; ++i) total += copy[i] - copy[i - 1];
int q; cin >> q; for (int i = 0; i < q; ++i) { int index, x; cin >> index >> x; if (n == 1) { data[0] = x; cout << x << ' '; continue; } int old = data[index - 1];
constauto newIter = cnt.upper_bound(x); if (newIter == cnt.end()) { ar = am = 0; auto iter = newIter; iter--; al = x - iter->first; } elseif (newIter == cnt.begin()) { al = am = 0; ar = newIter->first - x; } else { int lv, rv = newIter->first; auto tmp = newIter; --tmp; lv = tmp->first; al = x - lv; ar = rv - x; am = rv - lv; } cnt[x]++;
auto del = [&](int t) { auto iter = dif.find(t); if (iter == dif.end()) return; if (iter->second == 1) dif.erase(iter); else iter->second--; };