diff --git a/codeforces/995/.clang-format b/codeforces/995/.clang-format new file mode 100644 index 0000000..e7350c4 --- /dev/null +++ b/codeforces/995/.clang-format @@ -0,0 +1,9 @@ +BasedOnStyle: Google +AllowShortBlocksOnASingleLine: false +AllowShortCaseLabelsOnASingleLine: false +AllowShortCompoundRequirementOnASingleLine: false +AllowShortEnumsOnASingleLine: false +AllowShortFunctionsOnASingleLine: false +AllowShortIfStatementsOnASingleLine: false +AllowShortLambdasOnASingleLine: false +AllowShortLoopsOnASingleLine: false diff --git a/codeforces/995/.clangd b/codeforces/995/.clangd new file mode 100644 index 0000000..5b59a31 --- /dev/null +++ b/codeforces/995/.clangd @@ -0,0 +1,34 @@ +CompileFlags: + Add: + -O2 + -Wall + -Wextra + -Wpedantic + -Wshadow + -Wformat=2 + -Wfloat-equal + -Wlogical-op + -Wshift-overflow=2 + -Wnon-virtual-dtor + -Wold-style-cast + -Wcast-qual + -Wuseless-cast + -Wno-sign-promotion + -Wcast-align + -Wunused + -Woverloaded-virtual + -Wconversion + -Wsign-conversion + -Wmisleading-indentation + -Wduplicated-cond + -Wduplicated-branches + -Wlogical-op + -Wnull-dereference + -Wformat=2 + -Wformat-overflow + -Wformat-truncation + -Wdouble-promotion + -Wundef + -DLOCAL + -std=c++20 + -Wno-unknown-pragmas diff --git a/codeforces/995/a.cc b/codeforces/995/a.cc new file mode 100644 index 0000000..f1209b0 --- /dev/null +++ b/codeforces/995/a.cc @@ -0,0 +1,89 @@ +#include // {{{ + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +using i32 = int32_t; +using u32 = uint32_t; +using i64 = int64_t; +using u64 = uint64_t; +using d64 = double; +using d128 = long double; +template +using vec = std::vector; +template +using arr = std::array; +template +using pai = std::pair; + +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() + +#ifdef LOCAL +#define db(...) std::print(__VA_ARGS__) +#define dbln(...) std::println(__VA_ARGS__) +#else +#define db(...) +#define dbln(...) +#endif +// }}} + +void solve() { + u32 n; + cin >> n; + vec a(n), b(n); + for (auto& e : a) + cin >> e; + for (auto& e : b) + cin >> e; + b.emplace_back(0); + u64 ans = 0; + for (u32 i = 0; i < n; ++i) { + if (a[i] > b[i + 1]) + ans += a[i] - b[i + 1]; + } + cout << ans << '\n'; +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + cin.exceptions(cin.failbit); + + int tc = 1; + cin >> tc; + + for (int t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/995/b.cc b/codeforces/995/b.cc new file mode 100644 index 0000000..125c9b7 --- /dev/null +++ b/codeforces/995/b.cc @@ -0,0 +1,98 @@ +#include // {{{ + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +using i32 = int32_t; +using u32 = uint32_t; +using i64 = int64_t; +using u64 = uint64_t; +using d64 = double; +using d128 = long double; +template +using vec = std::vector; +template +using arr = std::array; +template +using pai = std::pair; + +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() + +#ifdef LOCAL +#define db(...) std::print(__VA_ARGS__) +#define dbln(...) std::println(__VA_ARGS__) +#else +#define db(...) +#define dbln(...) +#endif +// }}} + +void solve() { + i64 n, a, b, c; + cin >> n >> a >> b >> c; + + i64 ans = 3 * (n / (a + b + c)); + i64 rest = n % (a + b + c); + + if (rest == 0) { + cout << ans << '\n'; + return; + } + + if (rest <= a) { + cout << ans + 1 << '\n'; + return; + } + rest -= a; + + if (rest <= b) { + cout << ans + 2 << '\n'; + return; + } + + cout << ans + 3 << '\n'; +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + cin.exceptions(cin.failbit); + + int tc = 1; + cin >> tc; + + for (int t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/995/c.cc b/codeforces/995/c.cc new file mode 100644 index 0000000..2525e7b --- /dev/null +++ b/codeforces/995/c.cc @@ -0,0 +1,100 @@ +#include // {{{ + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +using i32 = int32_t; +using u32 = uint32_t; +using i64 = int64_t; +using u64 = uint64_t; +using d64 = double; +using d128 = long double; +template +using vec = std::vector; +template +using arr = std::array; +template +using pai = std::pair; + +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() + +#ifdef LOCAL +#define db(...) std::print(__VA_ARGS__) +#define dbln(...) std::println(__VA_ARGS__) +#else +#define db(...) +#define dbln(...) +#endif +// }}} + +bitset<3 * 100000 + 1> know; + +void solve() { + u64 n, m, k; + cin >> n >> m >> k; + know.reset(); + + vec M(m); + for (auto& e : M) + cin >> e; + u64 x; + for (u32 i = 0; i < k; ++i) { + cin >> x; + know[x] = 1; + } + + for (auto e : M) { + if (know[e] && k - 1 == n - 1) + cout << '1'; + else if (!know[e] && k == n - 1) + cout << '1'; + else + cout << '0'; + } + + cout << '\n'; +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + cin.exceptions(cin.failbit); + + int tc = 1; + cin >> tc; + + for (int t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/995/compile_flags.txt b/codeforces/995/compile_flags.txt new file mode 100644 index 0000000..5725a8c --- /dev/null +++ b/codeforces/995/compile_flags.txt @@ -0,0 +1,31 @@ +-O2 +-Wall +-Wextra +-Wpedantic +-Wshadow +-Wformat=2 +-Wfloat-equal +-Wlogical-op +-Wshift-overflow=2 +-Wnon-virtual-dtor +-Wold-style-cast +-Wcast-qual +-Wuseless-cast +-Wno-sign-promotion +-Wcast-align +-Wunused +-Woverloaded-virtual +-Wconversion +-Wsign-conversion +-Wmisleading-indentation +-Wduplicated-cond +-Wduplicated-branches +-Wlogical-op +-Wnull-dereference +-Wformat=2 +-Wformat-overflow +-Wformat-truncation +-Wdouble-promotion +-Wundef +-DLOCAL +-std=c++23 diff --git a/codeforces/995/d.cc b/codeforces/995/d.cc new file mode 100644 index 0000000..2074c86 --- /dev/null +++ b/codeforces/995/d.cc @@ -0,0 +1,101 @@ +#include // {{{ + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +using i32 = int32_t; +using u32 = uint32_t; +using i64 = int64_t; +using u64 = uint64_t; +using d64 = double; +using d128 = long double; +template +using vec = std::vector; +template +using arr = std::array; +template +using pai = std::pair; + +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() + +#ifdef LOCAL +#define db(...) std::print(__VA_ARGS__) +#define dbln(...) std::println(__VA_ARGS__) +#else +#define db(...) +#define dbln(...) +#endif +// }}} + +void solve() { + u64 n; + i64 x, y; + cin >> n >> x >> y; + vec a(n); + i64 total = 0; + for (auto& e : a) { + cin >> e; + total += e; + } + sort(all(a)); + + auto count = [&](i64 target) { + i64 ans = 0; + i32 j = n - 1; + for (i32 i = 0; i < n; ++i) { + while (j > i && a[i] + a[j] > target) { + --j; + } + if (j > i) { + ans += j - i; + } + } + return ans; + }; + + cout << count(total - x) - count(total - y - 1) << '\n'; +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + cin.exceptions(cin.failbit); + + int tc = 1; + cin >> tc; + + for (int t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/995/debug_flags.txt b/codeforces/995/debug_flags.txt new file mode 100644 index 0000000..03cba1b --- /dev/null +++ b/codeforces/995/debug_flags.txt @@ -0,0 +1,12 @@ +-g3 +-fsanitize=address,undefined +-fsanitize=float-divide-by-zero +-fsanitize=float-cast-overflow +-fno-sanitize-recover=all +-fstack-protector-all +-fstack-usage +-fno-omit-frame-pointer +-fno-inline +-ffunction-sections +-D_GLIBCXX_DEBUG +-D_GLIBCXX_DEBUG_PEDANTIC diff --git a/codeforces/995/e.cc b/codeforces/995/e.cc new file mode 100644 index 0000000..b0be64d --- /dev/null +++ b/codeforces/995/e.cc @@ -0,0 +1,107 @@ +#include // {{{ + +// https://codeforces.com/blog/entry/96344 + +#pragma GCC optimize("O2,unroll-loops") +#pragma GCC target("avx2,bmi,bmi2,lzcnt,popcnt") + +using namespace std; + +using i32 = int32_t; +using u32 = uint32_t; +using i64 = int64_t; +using u64 = uint64_t; +using d64 = double; +using d128 = long double; +template +using vec = std::vector; +template +using arr = std::array; +template +using pai = std::pair; + +template +constexpr T MIN = std::numeric_limits::min(); + +template +constexpr T MAX = std::numeric_limits::max(); + +template +[[nodiscard]] static T sc(auto&& x) { + return static_cast(x); +} + +template +[[nodiscard]] static T sz(auto&& x) { + return static_cast(x.size()); +} + +static void NO() { + std::cout << "NO\n"; +} + +static void YES() { + std::cout << "YES\n"; +} + +#define all(x) (x).begin(), (x).end() +#define rall(x) (x).rbegin(), (x).rend() + +#ifdef LOCAL +#define db(...) std::print(__VA_ARGS__) +#define dbln(...) std::println(__VA_ARGS__) +#else +#define db(...) +#define dbln(...) +#endif +// }}} + +void solve() { + i64 n, k; + cin >> n >> k; + vec a(n), b(n); + for (auto& e : a) + cin >> e; + for (auto& e : b) { + cin >> e; + } + + i64 ans = 0; + vec prices; + for (i64 i = 0; i < n; ++i) { + prices.push_back(a[i]); + prices.push_back(b[i]); + } + prices.push_back(0); + sort(all(prices)); + prices.erase(unique(all(prices)), prices.end()); + sort(all(a)); + sort(all(b)); + + for (i64 price : prices) { + i64 A = n - distance(a.begin(), lower_bound(all(a), price)); + i64 B = n - distance(b.begin(), lower_bound(all(b), price)); + i64 profit = price * B; + + if (B - A <= k) { + ans = max(ans, profit); + } + } + + cout << ans << '\n'; +} + +int main() { // {{{ + cin.tie(nullptr)->sync_with_stdio(false); + cin.exceptions(cin.failbit); + + int tc = 1; + cin >> tc; + + for (int t = 0; t < tc; ++t) { + solve(); + } + + return 0; +} +// }}} diff --git a/codeforces/995/io/a.in b/codeforces/995/io/a.in new file mode 100644 index 0000000..f6f30bd --- /dev/null +++ b/codeforces/995/io/a.in @@ -0,0 +1,13 @@ +4 +2 +3 2 +2 1 +1 +5 +8 +3 +1 1 1 +2 2 2 +6 +8 2 5 6 2 6 +8 2 7 4 3 4 diff --git a/codeforces/995/io/a.out b/codeforces/995/io/a.out new file mode 100644 index 0000000..09bc656 --- /dev/null +++ b/codeforces/995/io/a.out @@ -0,0 +1,7 @@ +4 +5 +1 +16 + +[code]: 0 +[time]: 3.49522 ms \ No newline at end of file diff --git a/codeforces/995/io/b.in b/codeforces/995/io/b.in new file mode 100644 index 0000000..14db487 --- /dev/null +++ b/codeforces/995/io/b.in @@ -0,0 +1,5 @@ +4 +12 1 5 3 +6 6 7 4 +16 3 4 1 +1000000000 1 1 1 diff --git a/codeforces/995/io/b.out b/codeforces/995/io/b.out new file mode 100644 index 0000000..76d9452 --- /dev/null +++ b/codeforces/995/io/b.out @@ -0,0 +1,7 @@ +5 +1 +6 +1000000000 + +[code]: 0 +[time]: 4.673 ms \ No newline at end of file diff --git a/codeforces/995/io/c.in b/codeforces/995/io/c.in new file mode 100644 index 0000000..e330ea6 --- /dev/null +++ b/codeforces/995/io/c.in @@ -0,0 +1,13 @@ +4 +4 4 3 +1 2 3 4 +1 3 4 +5 4 3 +1 2 3 4 +1 3 4 +4 4 4 +1 2 3 4 +1 2 3 4 +2 2 1 +1 2 +2 diff --git a/codeforces/995/io/c.out b/codeforces/995/io/c.out new file mode 100644 index 0000000..575d04a --- /dev/null +++ b/codeforces/995/io/c.out @@ -0,0 +1,7 @@ +0100 +0000 +1111 +10 + +[code]: 0 +[time]: 4.60768 ms \ No newline at end of file diff --git a/codeforces/995/io/d.in b/codeforces/995/io/d.in new file mode 100644 index 0000000..eaf4088 --- /dev/null +++ b/codeforces/995/io/d.in @@ -0,0 +1,15 @@ +7 +4 8 10 +4 6 3 6 +6 22 27 +4 9 6 3 4 5 +3 8 10 +3 2 1 +3 1 1 +2 3 4 +3 3 6 +3 2 1 +4 4 12 +3 3 2 1 +6 8 8 +1 1 2 2 2 3 diff --git a/codeforces/995/io/d.out b/codeforces/995/io/d.out new file mode 100644 index 0000000..4c6d55a --- /dev/null +++ b/codeforces/995/io/d.out @@ -0,0 +1,10 @@ +4 +7 +0 +0 +1 +5 +6 + +[code]: 0 +[time]: 4.89306 ms \ No newline at end of file diff --git a/codeforces/995/io/e.in b/codeforces/995/io/e.in new file mode 100644 index 0000000..e27c27c --- /dev/null +++ b/codeforces/995/io/e.in @@ -0,0 +1,16 @@ +5 +2 0 +2 1 +3 4 +1 1 +2 +5 +3 3 +1 5 2 +3 6 4 +4 3 +2 3 2 8 +3 7 3 9 +3 1 +2 9 5 +12 14 9 diff --git a/codeforces/995/io/e.out b/codeforces/995/io/e.out new file mode 100644 index 0000000..f3bfaba --- /dev/null +++ b/codeforces/995/io/e.out @@ -0,0 +1,8 @@ +2 +5 +9 +14 +15 + +[code]: 0 +[time]: 4.36282 ms \ No newline at end of file diff --git a/codeforces/995/makefile b/codeforces/995/makefile new file mode 100644 index 0000000..9c5450b --- /dev/null +++ b/codeforces/995/makefile @@ -0,0 +1,28 @@ +.PHONY: run debug clean setup init + +SRC = $(word 2,$(MAKECMDGOALS)) + +.SILENT: + +run: + sh scripts/run.sh $(SRC) + +debug: + sh scripts/debug.sh $(SRC) + +clean: + rm -rf build/* + +setup: + test -d build || mkdir -p build + test -d io || mkdir -p io + test -d scripts || mkdir -p scripts + test -f compile_flags.txt || cp $(HOME)/.config/cp-template/compile_flags.txt . + test -f .clangd || cp $(HOME)/.config/cp-template/.clangd . + test -f .clang-format || cp $(HOME)/.config/cp-template/.clang-format . + +init: + make setup + +%: + @: diff --git a/codeforces/995/scripts/debug.sh b/codeforces/995/scripts/debug.sh new file mode 100644 index 0000000..2979422 --- /dev/null +++ b/codeforces/995/scripts/debug.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +. ./scripts/utils.sh + +SRC="$1" +BASE=$(basename "$SRC" .cc) +INPUT="${BASE}.in" +OUTPUT="${BASE}.out" +DBG_BIN="${BASE}.debug" + +test -d build || mkdir -p build +test -d io || mkdir -p io + +test -f "$INPUT" && test ! -f "io/$INPUT" && mv "$INPUT" "io/" +test -f "$OUTPUT" && test ! -f "io/$OUTPUT" && mv "$OUTPUT" "io/" + +test -f "io/$INPUT" || touch "io/$INPUT" +test -f "io/$OUTPUT" || touch "io/$OUTPUT" + +INPUT="io/$INPUT" +OUTPUT="io/$OUTPUT" +DBG_BIN="build/$DBG_BIN" + +compile_source "$SRC" "$DBG_BIN" "$OUTPUT" @debug_flags.txt +CODE=$? +test $CODE -gt 0 && exit $CODE + +execute_binary "$DBG_BIN" "$INPUT" "$OUTPUT" +exit $? diff --git a/codeforces/995/scripts/run.sh b/codeforces/995/scripts/run.sh new file mode 100644 index 0000000..ab9aa7d --- /dev/null +++ b/codeforces/995/scripts/run.sh @@ -0,0 +1,29 @@ +#!/bin/sh + +. ./scripts/utils.sh + +SRC="$1" +BASE=$(basename "$SRC" .cc) +INPUT="${BASE}.in" +OUTPUT="${BASE}.out" +RUN_BIN="${BASE}.run" + +test -d build || mkdir -p build +test -d io || mkdir -p io + +test -f "$INPUT" && test ! -f "io/$INPUT" && mv "$INPUT" "io/" +test -f "$OUTPUT" && test ! -f "io/$OUTPUT" && mv "$OUTPUT" "io/" + +test -f "io/$INPUT" || touch "io/$INPUT" +test -f "io/$OUTPUT" || touch "io/$OUTPUT" + +INPUT="io/$INPUT" +OUTPUT="io/$OUTPUT" +RUN_BIN="build/$RUN_BIN" + +compile_source "$SRC" "$RUN_BIN" "$OUTPUT" "" +CODE=$? +test $CODE -gt 0 && exit $CODE + +execute_binary "$RUN_BIN" "$INPUT" "$OUTPUT" +exit $? diff --git a/codeforces/995/scripts/utils.sh b/codeforces/995/scripts/utils.sh new file mode 100644 index 0000000..e99b25b --- /dev/null +++ b/codeforces/995/scripts/utils.sh @@ -0,0 +1,53 @@ +#!/bin/sh + +execute_binary() { + binary="$1" + input="$2" + output="$3" + + start=$(date '+%s.%N') + timeout 2s ./"$binary" <"$input" >"$output" 2>&1 + CODE=$? + end=$(date '+%s.%N') + truncate -s "$(head -n 1000 "$output" | wc -c)" "$output" + + if [ $CODE -ge 124 ]; then + MSG='' + case $CODE in + 124) MSG='TIMEOUT' ;; + 128) MSG='SIGILL' ;; + 130) MSG='SIGABRT' ;; + 131) MSG='SIGBUS' ;; + 136) MSG='SIGFPE' ;; + 135) MSG='SIGSEGV' ;; + 137) MSG='SIGPIPE' ;; + 139) MSG='SIGTERM' ;; + esac + [ $CODE -ne 124 ] && sed -i '$d' "$output" + test -n "$MSG" && printf '\n[code]: %s (%s)' "$CODE" "$MSG" >>"$output" + else + printf '\n[code]: %s' "$CODE" >>"$output" + fi + + printf '\n[time]: %s ms' "$(awk "BEGIN {print ($end - $start) * 1000}")" >>$output + return $CODE +} + +compile_source() { + src="$1" + bin="$2" + output="$3" + flags="$4" + + test -f "$bin" && rm "$bin" || true + g++ @compile_flags.txt $flags "$src" -o "$bin" 2>"$output" + CODE=$? + + if [ $CODE -gt 0 ]; then + printf '\n[code]: %s' "$CODE" >>"$output" + return $CODE + else + echo '' >"$output" + return 0 + fi +}