feat(cf): 894
This commit is contained in:
parent
ab4fbd97b2
commit
372c5d20a5
48 changed files with 2330 additions and 0 deletions
9
codeforces/894/.clang-format
Normal file
9
codeforces/894/.clang-format
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
BasedOnStyle: Google
|
||||
AllowShortBlocksOnASingleLine: false
|
||||
AllowShortCaseLabelsOnASingleLine: false
|
||||
AllowShortCompoundRequirementOnASingleLine: false
|
||||
AllowShortEnumsOnASingleLine: false
|
||||
AllowShortFunctionsOnASingleLine: false
|
||||
AllowShortIfStatementsOnASingleLine: false
|
||||
AllowShortLambdasOnASingleLine: false
|
||||
AllowShortLoopsOnASingleLine: false
|
||||
8
codeforces/894/.clangd
Normal file
8
codeforces/894/.clangd
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
CompileFlags:
|
||||
Add:
|
||||
- -Wall
|
||||
- -Wextra
|
||||
- -Wpedantic
|
||||
- -Wshadow
|
||||
- -DLOCAL
|
||||
- -Wno-unknown-pragmas
|
||||
103
codeforces/894/a.cc
Normal file
103
codeforces/894/a.cc
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MIN() {
|
||||
return std::numeric_limits<T>::min();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MAX() {
|
||||
return std::numeric_limits<T>::max();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto &&x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto &&x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
|
||||
#define prln(...) std::println(__VA_ARGS__)
|
||||
#define pr(...) std::print(__VA_ARGS__)
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbgln(...) std::println(__VA_ARGS__)
|
||||
#define dbg(...) std::print(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using ve = std::vector<T>;
|
||||
template <typename T, size_t N>
|
||||
using ar = std::array<T, N>;
|
||||
template <typename T1, typename T2>
|
||||
using pa = std::pair<T1, T2>;
|
||||
template <typename... Ts>
|
||||
using tu = std::tuple<Ts...>;
|
||||
template <typename... Ts>
|
||||
using dq = std::deque<Ts...>;
|
||||
template <typename... Ts>
|
||||
using qu = std::queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using pq = std::priority_queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using st = std::stack<Ts...>;
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
int n, m;
|
||||
cin >> n >> m;
|
||||
|
||||
vector<string> grid(n);
|
||||
for (auto &s : grid)
|
||||
cin >> s;
|
||||
string letters = "vika";
|
||||
int i = 0;
|
||||
|
||||
for (int col = 0; col < m; ++col) {
|
||||
for (int row = 0; row < n; ++row) {
|
||||
if (grid[row][col] == letters[i]) {
|
||||
if (++i == 4) {
|
||||
cout << "YES\n";
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
cout << "NO" << endl;
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
3
codeforces/894/a.in
Normal file
3
codeforces/894/a.in
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
1
|
||||
1 1
|
||||
v
|
||||
4
codeforces/894/a.out
Normal file
4
codeforces/894/a.out
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
NO
|
||||
|
||||
[code]: 0
|
||||
[time]: 14.0724 ms
|
||||
98
codeforces/894/b.cc
Normal file
98
codeforces/894/b.cc
Normal file
|
|
@ -0,0 +1,98 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MIN() {
|
||||
return std::numeric_limits<T>::min();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MAX() {
|
||||
return std::numeric_limits<T>::max();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto&& x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto&& x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
|
||||
#define prln(...) std::println(__VA_ARGS__)
|
||||
#define pr(...) std::print(__VA_ARGS__)
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbgln(...) std::println(__VA_ARGS__)
|
||||
#define dbg(...) std::print(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using ve = std::vector<T>;
|
||||
template <typename T, size_t N>
|
||||
using ar = std::array<T, N>;
|
||||
template <typename T1, typename T2>
|
||||
using pa = std::pair<T1, T2>;
|
||||
template <typename... Ts>
|
||||
using tu = std::tuple<Ts...>;
|
||||
template <typename... Ts>
|
||||
using dq = std::deque<Ts...>;
|
||||
template <typename... Ts>
|
||||
using qu = std::queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using pq = std::priority_queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using st = std::stack<Ts...>;
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
int n;
|
||||
cin >> n;
|
||||
ve<ll> b(n);
|
||||
for (auto& e : b)
|
||||
cin >> e;
|
||||
|
||||
ve<ll> ans{b[0]};
|
||||
for (int i = 1; i < n; ++i) {
|
||||
if (ans.back() > b[i]) {
|
||||
ans.eb(b[i]);
|
||||
}
|
||||
ans.eb(b[i]);
|
||||
}
|
||||
cout << ans.size() << endl;
|
||||
for (auto& e : ans)
|
||||
cout << e << ' ';
|
||||
cout << endl;
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
13
codeforces/894/b.in
Normal file
13
codeforces/894/b.in
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
6
|
||||
3
|
||||
4 6 3
|
||||
3
|
||||
1 2 3
|
||||
5
|
||||
1 7 9 5 7
|
||||
1
|
||||
144
|
||||
2
|
||||
1 1
|
||||
5
|
||||
1 2 2 1 1
|
||||
15
codeforces/894/b.out
Normal file
15
codeforces/894/b.out
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
4
|
||||
4 6 3 3
|
||||
3
|
||||
1 2 3
|
||||
6
|
||||
1 7 9 5 5 7
|
||||
1
|
||||
144
|
||||
2
|
||||
1 1
|
||||
6
|
||||
1 2 2 1 1 1
|
||||
|
||||
[code]: 0
|
||||
[time]: 14.2317 ms
|
||||
131
codeforces/894/c.cc
Normal file
131
codeforces/894/c.cc
Normal file
|
|
@ -0,0 +1,131 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MIN() {
|
||||
return std::numeric_limits<T>::min();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MAX() {
|
||||
return std::numeric_limits<T>::max();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto&& x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto&& x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
|
||||
#define prln(...) std::println(__VA_ARGS__)
|
||||
#define pr(...) std::print(__VA_ARGS__)
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbgln(...) std::println(__VA_ARGS__)
|
||||
#define dbg(...) std::print(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using ve = std::vector<T>;
|
||||
template <typename T, size_t N>
|
||||
using ar = std::array<T, N>;
|
||||
template <typename T1, typename T2>
|
||||
using pa = std::pair<T1, T2>;
|
||||
template <typename... Ts>
|
||||
using tu = std::tuple<Ts...>;
|
||||
template <typename... Ts>
|
||||
using dq = std::deque<Ts...>;
|
||||
template <typename... Ts>
|
||||
using qu = std::queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using pq = std::priority_queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using st = std::stack<Ts...>;
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
// }}}
|
||||
|
||||
inline static void NO() {
|
||||
prln("NO");
|
||||
}
|
||||
inline static void YES() {
|
||||
prln("YES");
|
||||
}
|
||||
|
||||
void solve() {
|
||||
int n;
|
||||
cin >> n;
|
||||
ve<int> a(n);
|
||||
for (auto& e : a)
|
||||
cin >> e;
|
||||
|
||||
ve<int> b(n, 0);
|
||||
int write = n - 1;
|
||||
|
||||
int y = 0;
|
||||
int i = 0;
|
||||
while (i < n) {
|
||||
++y;
|
||||
while (i + 1 < n && a[i] == a[i + 1]) {
|
||||
++y;
|
||||
++i;
|
||||
}
|
||||
if ((b[write] = y) != a[write]) {
|
||||
NO();
|
||||
return;
|
||||
};
|
||||
--write;
|
||||
if (i + 1 < n) {
|
||||
for (int j = 0; j < a[i] - a[i + 1] - 1; ++j) {
|
||||
if ((b[write] = y) != a[write]) {
|
||||
NO();
|
||||
return;
|
||||
}
|
||||
--write;
|
||||
}
|
||||
}
|
||||
++i;
|
||||
}
|
||||
|
||||
while (write >= 0) {
|
||||
if ((b[write] = y) != a[write]) {
|
||||
NO();
|
||||
return;
|
||||
}
|
||||
--write;
|
||||
}
|
||||
|
||||
YES();
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
15
codeforces/894/c.in
Normal file
15
codeforces/894/c.in
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
7
|
||||
5
|
||||
5 4 3 2 1
|
||||
3
|
||||
3 1 1
|
||||
3
|
||||
4 2 1
|
||||
1
|
||||
2
|
||||
5
|
||||
5 3 3 1 1
|
||||
5
|
||||
5 5 5 3 3
|
||||
2
|
||||
6 1
|
||||
10
codeforces/894/c.out
Normal file
10
codeforces/894/c.out
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
YES
|
||||
YES
|
||||
NO
|
||||
NO
|
||||
YES
|
||||
YES
|
||||
NO
|
||||
|
||||
[code]: 0
|
||||
[time]: 12.7897 ms
|
||||
6
codeforces/894/compile_flags.txt
Normal file
6
codeforces/894/compile_flags.txt
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
-Wall
|
||||
-Wextra
|
||||
-Wpedantic
|
||||
-Wshadow
|
||||
-DLOCAL
|
||||
-std=c++23
|
||||
94
codeforces/894/d.cc
Normal file
94
codeforces/894/d.cc
Normal file
|
|
@ -0,0 +1,94 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MIN() {
|
||||
return std::numeric_limits<T>::min();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MAX() {
|
||||
return std::numeric_limits<T>::max();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto&& x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto&& x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
|
||||
#define prln(...) std::println(__VA_ARGS__)
|
||||
#define pr(...) std::print(__VA_ARGS__)
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbgln(...) std::println(__VA_ARGS__)
|
||||
#define dbg(...) std::print(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using ve = std::vector<T>;
|
||||
template <typename T, size_t N>
|
||||
using ar = std::array<T, N>;
|
||||
template <typename T1, typename T2>
|
||||
using pa = std::pair<T1, T2>;
|
||||
template <typename... Ts>
|
||||
using tu = std::tuple<Ts...>;
|
||||
template <typename... Ts>
|
||||
using dq = std::deque<Ts...>;
|
||||
template <typename... Ts>
|
||||
using qu = std::queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using pq = std::priority_queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using st = std::stack<Ts...>;
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
// }}}
|
||||
|
||||
void solve() {
|
||||
ll n;
|
||||
cin >> n;
|
||||
ll l = 1, r = sqrt(2 * n) + 1;
|
||||
|
||||
while (l <= r) {
|
||||
ll m = l + (r - l) / 2;
|
||||
if (m * (m - 1) / 2 <= n) {
|
||||
l = m + 1;
|
||||
} else
|
||||
r = m - 1;
|
||||
}
|
||||
|
||||
cout << r + n - r * (r - 1) / 2 << endl;
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
6
codeforces/894/d.in
Normal file
6
codeforces/894/d.in
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
5
|
||||
1
|
||||
3
|
||||
6
|
||||
179
|
||||
1000000000000000000
|
||||
8
codeforces/894/d.out
Normal file
8
codeforces/894/d.out
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
2
|
||||
3
|
||||
4
|
||||
27
|
||||
2648956421
|
||||
|
||||
[code]: 0
|
||||
[time]: 12.2623 ms
|
||||
103
codeforces/894/e.cc
Normal file
103
codeforces/894/e.cc
Normal file
|
|
@ -0,0 +1,103 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MIN() {
|
||||
return std::numeric_limits<T>::min();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MAX() {
|
||||
return std::numeric_limits<T>::max();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto&& x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto&& x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
|
||||
#define prln(...) std::println(__VA_ARGS__)
|
||||
#define pr(...) std::print(__VA_ARGS__)
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbgln(...) std::println(__VA_ARGS__)
|
||||
#define dbg(...) std::print(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using ve = std::vector<T>;
|
||||
template <typename T, size_t N>
|
||||
using ar = std::array<T, N>;
|
||||
template <typename T1, typename T2>
|
||||
using pa = std::pair<T1, T2>;
|
||||
template <typename... Ts>
|
||||
using tu = std::tuple<Ts...>;
|
||||
template <typename... Ts>
|
||||
using dq = std::deque<Ts...>;
|
||||
template <typename... Ts>
|
||||
using qu = std::queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using pq = std::priority_queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using st = std::stack<Ts...>;
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
// }}}
|
||||
|
||||
ll n, m, d;
|
||||
void solve() {
|
||||
cin >> n >> m >> d;
|
||||
|
||||
ll ans = 0;
|
||||
ll sum = 0;
|
||||
multiset<ll> tree;
|
||||
ll x;
|
||||
for (int i = 0; i < n; ++i) {
|
||||
cin >> x;
|
||||
if (x > 0) {
|
||||
sum += x;
|
||||
tree.insert(x);
|
||||
}
|
||||
if (sz<int>(tree) > m) {
|
||||
sum -= *tree.begin();
|
||||
tree.erase(tree.begin());
|
||||
}
|
||||
|
||||
ans = max(ans, sum - d * (i + 1));
|
||||
}
|
||||
|
||||
prln("{}", ans);
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
13
codeforces/894/e.in
Normal file
13
codeforces/894/e.in
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
6
|
||||
5 2 2
|
||||
3 2 5 4 6
|
||||
4 3 2
|
||||
1 1 1 1
|
||||
6 6 6
|
||||
-82 45 1 -77 39 11
|
||||
5 2 2
|
||||
3 2 5 4 8
|
||||
2 1 1
|
||||
-1 2
|
||||
6 3 2
|
||||
-8 8 -2 -1 9 0
|
||||
9
codeforces/894/e.out
Normal file
9
codeforces/894/e.out
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
2
|
||||
0
|
||||
60
|
||||
3
|
||||
0
|
||||
7
|
||||
|
||||
[code]: 0
|
||||
[time]: 12.3913 ms
|
||||
117
codeforces/894/f.cc
Normal file
117
codeforces/894/f.cc
Normal file
|
|
@ -0,0 +1,117 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MIN() {
|
||||
return std::numeric_limits<T>::min();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MAX() {
|
||||
return std::numeric_limits<T>::max();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto&& x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto&& x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
|
||||
#define prln(...) std::println(__VA_ARGS__)
|
||||
#define pr(...) std::print(__VA_ARGS__)
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbgln(...) std::println(__VA_ARGS__)
|
||||
#define dbg(...) std::print(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
inline static void NO() {
|
||||
prln("NO");
|
||||
}
|
||||
|
||||
inline static void YES() {
|
||||
prln("YES");
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using ve = std::vector<T>;
|
||||
template <typename T, size_t N>
|
||||
using ar = std::array<T, N>;
|
||||
template <typename T1, typename T2>
|
||||
using pa = std::pair<T1, T2>;
|
||||
template <typename... Ts>
|
||||
using tu = std::tuple<Ts...>;
|
||||
template <typename... Ts>
|
||||
using dq = std::deque<Ts...>;
|
||||
template <typename... Ts>
|
||||
using qu = std::queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using pq = std::priority_queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using st = std::stack<Ts...>;
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
// }}}
|
||||
|
||||
ll w, f;
|
||||
void solve() {
|
||||
cin >> w >> f;
|
||||
int n;
|
||||
cin >> n;
|
||||
ll total = 0;
|
||||
|
||||
ve<int> strengths(n);
|
||||
for (int i = 0; i < n; ++i) {
|
||||
cin >> strengths[i];
|
||||
total += strengths[i];
|
||||
}
|
||||
|
||||
ve<ll> dp(total + 1, false);
|
||||
dp[0] = true;
|
||||
for (int i = 0; i < n; ++i) {
|
||||
for (int j = total; j >= strengths[i]; --j) {
|
||||
dp[j] = dp[j] || dp[j - strengths[i]];
|
||||
}
|
||||
}
|
||||
|
||||
ll ans = MAX<ll>();
|
||||
for (int i = 0; i <= total; ++i) {
|
||||
if (dp[i]) {
|
||||
ans = min(ans, max((i + w - 1) / w, (total - i + f - 1) / f));
|
||||
}
|
||||
}
|
||||
|
||||
cout << ans << endl;
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
13
codeforces/894/f.in
Normal file
13
codeforces/894/f.in
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
4
|
||||
2 3
|
||||
3
|
||||
2 6 7
|
||||
37 58
|
||||
1
|
||||
93
|
||||
190 90
|
||||
2
|
||||
23 97
|
||||
13 4
|
||||
4
|
||||
10 10 2 45
|
||||
7
codeforces/894/f.out
Normal file
7
codeforces/894/f.out
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
3
|
||||
2
|
||||
1
|
||||
5
|
||||
|
||||
[code]: 0
|
||||
[time]: 7.07388 ms
|
||||
232
codeforces/894/g.cc
Normal file
232
codeforces/894/g.cc
Normal file
|
|
@ -0,0 +1,232 @@
|
|||
#include <bits/stdc++.h> // {{{
|
||||
|
||||
// https://codeforces.com/blog/entry/96344
|
||||
|
||||
#pragma GCC optimize("O2,unroll-loops")
|
||||
#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt")
|
||||
|
||||
using namespace std;
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MIN() {
|
||||
return std::numeric_limits<T>::min();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T MAX() {
|
||||
return std::numeric_limits<T>::max();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sc(auto &&x) {
|
||||
return static_cast<T>(x);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
[[nodiscard]] static T sz(auto &&x) {
|
||||
return static_cast<T>(x.size());
|
||||
}
|
||||
|
||||
#define prln(...) std::println(__VA_ARGS__)
|
||||
#define pr(...) std::print(__VA_ARGS__)
|
||||
|
||||
#ifdef LOCAL
|
||||
#define dbgln(...) std::println(__VA_ARGS__)
|
||||
#define dbg(...) std::print(__VA_ARGS__)
|
||||
#endif
|
||||
|
||||
inline static void NO() {
|
||||
prln("NO");
|
||||
}
|
||||
|
||||
inline static void YES() {
|
||||
prln("YES");
|
||||
}
|
||||
|
||||
using ll = long long;
|
||||
using ld = long double;
|
||||
template <typename T>
|
||||
using ve = std::vector<T>;
|
||||
template <typename T, size_t N>
|
||||
using ar = std::array<T, N>;
|
||||
template <typename T1, typename T2>
|
||||
using pa = std::pair<T1, T2>;
|
||||
template <typename... Ts>
|
||||
using tu = std::tuple<Ts...>;
|
||||
template <typename... Ts>
|
||||
using dq = std::deque<Ts...>;
|
||||
template <typename... Ts>
|
||||
using qu = std::queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using pq = std::priority_queue<Ts...>;
|
||||
template <typename... Ts>
|
||||
using st = std::stack<Ts...>;
|
||||
|
||||
#define ff first
|
||||
#define ss second
|
||||
#define eb emplace_back
|
||||
#define pb push_back
|
||||
#define all(x) (x).begin(), (x).end()
|
||||
#define rall(x) (x).rbegin(), (x).rend()
|
||||
// }}}
|
||||
|
||||
#include <ext/pb_ds/assoc_container.hpp>
|
||||
#include <ext/pb_ds/tree_policy.hpp>
|
||||
|
||||
using namespace __gnu_pbds;
|
||||
|
||||
// https://mirror.codeforces.com/blog/entry/124683
|
||||
|
||||
namespace hashing {
|
||||
using i64 = std::int64_t;
|
||||
using u64 = std::uint64_t;
|
||||
static const u64 FIXED_RANDOM =
|
||||
std::chrono::steady_clock::now().time_since_epoch().count();
|
||||
|
||||
#if USE_AES
|
||||
std::mt19937 rd(FIXED_RANDOM);
|
||||
const __m128i KEY1{(i64)rd(), (i64)rd()};
|
||||
const __m128i KEY2{(i64)rd(), (i64)rd()};
|
||||
#endif
|
||||
|
||||
template <class T, class D = void>
|
||||
struct custom_hash {};
|
||||
|
||||
template <class T>
|
||||
inline void hash_combine(u64 &seed, T const &v) {
|
||||
custom_hash<T> hasher;
|
||||
seed ^= hasher(v) + 0x9e3779b97f4a7c15 + (seed << 12) + (seed >> 4);
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct custom_hash<T,
|
||||
typename std::enable_if<std::is_integral<T>::value>::type> {
|
||||
u64 operator()(T _x) const {
|
||||
u64 x = _x;
|
||||
#if USE_AES
|
||||
__m128i m{i64(u64(x) * 0xbf58476d1ce4e5b9u64), (i64)FIXED_RANDOM};
|
||||
__m128i y = _mm_aesenc_si128(m, KEY1);
|
||||
__m128i z = _mm_aesenc_si128(y, KEY2);
|
||||
return z[0];
|
||||
#else
|
||||
x += 0x9e3779b97f4a7c15 + FIXED_RANDOM;
|
||||
x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
|
||||
x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
|
||||
return x ^ (x >> 31);
|
||||
#endif
|
||||
}
|
||||
};
|
||||
|
||||
template <class T>
|
||||
struct custom_hash<T, std::void_t<decltype(std::begin(std::declval<T>()))>> {
|
||||
u64 operator()(T const &a) const {
|
||||
u64 value = FIXED_RANDOM;
|
||||
for (auto &x : a)
|
||||
hash_combine(value, x);
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
template <class... T>
|
||||
struct custom_hash<std::tuple<T...>> {
|
||||
u64 operator()(const std::tuple<T...> &a) const {
|
||||
u64 value = FIXED_RANDOM;
|
||||
std::apply(
|
||||
[&value](T const &...args) {
|
||||
(hash_combine(value, args), ...);
|
||||
},
|
||||
a);
|
||||
return value;
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class U>
|
||||
struct custom_hash<std::pair<T, U>> {
|
||||
u64 operator()(std::pair<T, U> const &a) const {
|
||||
u64 value = FIXED_RANDOM;
|
||||
hash_combine(value, a.first);
|
||||
hash_combine(value, a.second);
|
||||
return value;
|
||||
}
|
||||
};
|
||||
}; // namespace hashing
|
||||
|
||||
#ifdef PB_DS_ASSOC_CNTNR_HPP
|
||||
template <class Key, class Value = null_type>
|
||||
using hashtable = gp_hash_table<
|
||||
Key, Value, hashing::custom_hash<Key>, std::equal_to<Key>,
|
||||
direct_mask_range_hashing<>, linear_probe_fn<>,
|
||||
hash_standard_resize_policy<hash_exponential_size_policy<>,
|
||||
hash_load_check_resize_trigger<>, true>>;
|
||||
|
||||
#endif
|
||||
#ifdef PB_DS_TREE_POLICY_HPP
|
||||
template <typename T>
|
||||
using multitree = tree<T, null_type, std::less_equal<T>, rb_tree_tag,
|
||||
tree_order_statistics_node_update>;
|
||||
template <class Key, class Value = null_type>
|
||||
using rbtree = tree<Key, Value, std::less<Key>, rb_tree_tag,
|
||||
tree_order_statistics_node_update>;
|
||||
#endif
|
||||
|
||||
int n, q;
|
||||
void solve() {
|
||||
cin >> n;
|
||||
ve<int> a(n);
|
||||
multitree<int> values;
|
||||
|
||||
for (auto &e : a) {
|
||||
cin >> e;
|
||||
values.insert(e);
|
||||
}
|
||||
|
||||
multitree<int> tree;
|
||||
for (auto it = next(values.begin()); it != values.end(); ++it) {
|
||||
tree.insert(*it - *prev(it));
|
||||
}
|
||||
|
||||
int i, x;
|
||||
cin >> q;
|
||||
while (q--) {
|
||||
cin >> i >> x;
|
||||
--i;
|
||||
// NOTE: this is not removing the exact right value among duplicates
|
||||
dbgln("update: i={}, x={}", i, x);
|
||||
if (i) {
|
||||
auto it = values.find(a[i]);
|
||||
dbgln("removing {}", *it - *prev(it));
|
||||
tree.erase(*it - *prev(it));
|
||||
dbgln("adding diff {}", abs(*prev(it) - x));
|
||||
tree.insert(abs(*prev(it) - x));
|
||||
}
|
||||
if (i != n - 1) {
|
||||
dbgln("removing {}", *it - *next(it));
|
||||
tree.erase(*it - *next(it));
|
||||
dbgln("adding {}", abs(*next(it) - x));
|
||||
tree.insert(abs(*next(it) - x));
|
||||
}
|
||||
values.erase(a[i]);
|
||||
a[i] = x;
|
||||
|
||||
int ans = *--values.end();
|
||||
if (!tree.empty())
|
||||
ans += *--tree.end();
|
||||
pr("{} ", ans);
|
||||
}
|
||||
prln();
|
||||
}
|
||||
|
||||
int main() { // {{{
|
||||
cin.tie(nullptr)->sync_with_stdio(false);
|
||||
cin.exceptions(cin.failbit);
|
||||
|
||||
int t = 1;
|
||||
cin >> t;
|
||||
|
||||
while (t--) {
|
||||
solve();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
// }}}
|
||||
34
codeforces/894/g.in
Normal file
34
codeforces/894/g.in
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
4
|
||||
3
|
||||
2 4 8
|
||||
3
|
||||
1 6
|
||||
2 10
|
||||
3 1
|
||||
5
|
||||
1 2 2 2 2
|
||||
1
|
||||
5 3
|
||||
2
|
||||
5 6
|
||||
7
|
||||
1 2
|
||||
1 7
|
||||
1 7
|
||||
2 5
|
||||
1 2
|
||||
2 7
|
||||
2 2
|
||||
5
|
||||
2 5 1 10 6
|
||||
10
|
||||
1 7
|
||||
4 8
|
||||
2 5
|
||||
1 4
|
||||
2 8
|
||||
3 4
|
||||
1 9
|
||||
3 7
|
||||
3 4
|
||||
3 1
|
||||
86
codeforces/894/g.out
Normal file
86
codeforces/894/g.out
Normal file
|
|
@ -0,0 +1,86 @@
|
|||
update: i=0, x=6
|
||||
removing -2
|
||||
adding 4
|
||||
12 update: i=1, x=10
|
||||
removing -8
|
||||
adding diff 2
|
||||
removing -2
|
||||
adding 8
|
||||
16 update: i=2, x=1
|
||||
removing -8
|
||||
adding diff 7
|
||||
16
|
||||
update: i=4, x=3
|
||||
removing -2
|
||||
adding diff 1
|
||||
3
|
||||
update: i=0, x=2
|
||||
removing -4
|
||||
adding 3
|
||||
9 update: i=0, x=7
|
||||
removing -4
|
||||
adding 2
|
||||
9 update: i=0, x=7
|
||||
removing -4
|
||||
adding 2
|
||||
9 update: i=1, x=5
|
||||
removing -5
|
||||
adding diff 1
|
||||
9 update: i=0, x=2
|
||||
removing -4
|
||||
adding 3
|
||||
9 update: i=1, x=7
|
||||
removing -5
|
||||
adding diff 1
|
||||
9 update: i=1, x=2
|
||||
removing -5
|
||||
adding diff 4
|
||||
10
|
||||
update: i=0, x=7
|
||||
removing 2
|
||||
adding 6
|
||||
16 update: i=3, x=8
|
||||
removing -7
|
||||
adding diff 2
|
||||
removing 2
|
||||
adding 7
|
||||
17 update: i=1, x=5
|
||||
removing -7
|
||||
adding diff 5
|
||||
removing 2
|
||||
adding 4
|
||||
17 update: i=0, x=4
|
||||
removing 2
|
||||
adding 3
|
||||
17 update: i=1, x=8
|
||||
removing -7
|
||||
adding diff 2
|
||||
removing 2
|
||||
adding 7
|
||||
17 update: i=2, x=4
|
||||
removing -7
|
||||
adding diff 6
|
||||
removing 2
|
||||
adding 3
|
||||
17 update: i=0, x=9
|
||||
removing 2
|
||||
adding 8
|
||||
18 update: i=2, x=7
|
||||
removing -7
|
||||
adding diff 3
|
||||
removing 2
|
||||
adding 6
|
||||
18 update: i=2, x=4
|
||||
removing -7
|
||||
adding diff 6
|
||||
removing 2
|
||||
adding 3
|
||||
18 update: i=2, x=1
|
||||
removing -7
|
||||
adding diff 9
|
||||
removing 2
|
||||
adding 0
|
||||
19
|
||||
|
||||
[code]: 0
|
||||
[time]: 14.2844 ms
|
||||
Loading…
Add table
Add a link
Reference in a new issue