結果
| 問題 | No.3684 chokudai_niku.png |
| コンテスト | |
| ユーザー |
秋ナス🍆
|
| 提出日時 | 2026-09-05 13:16:00 |
| 言語 | C++23(gcc16) (gcc 16.1.0 + boost 1.92.0 + ACL) |
| 結果 |
AC
不安定
|
| 実行時間 | 27 ms / 2,000 ms |
| + 960µs | |
| コード長 | 11,253 bytes |
| 記録 | |
| コンパイル時間 | 5,209 ms |
| コンパイル使用メモリ | 398,776 KB |
| 実行使用メモリ | 15,924 KB |
| 最終ジャッジ日時 | 2026-09-05 13:16:16 |
| 合計ジャッジ時間 | 11,812 ms |
|
ジャッジサーバーID (参考情報) |
judge2_0 / judge1_0 |
(要ログイン)
| ファイルパターン | 結果 |
|---|---|
| sample | AC * 3 |
| other | AC * 44 |
ソースコード
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <string>
#include <tuple>
#include <type_traits>
#include <utility>
#include <vector>
struct FastIO {
FastIO() {
std::ios_base::sync_with_stdio(false);
std::cin.tie(nullptr);
}
};
inline FastIO fast_io_init;
template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& v);
template <typename T1, typename T2>
std::istream& operator>>(std::istream& is, std::pair<T1, T2>& p) {
return is >> p.first >> p.second;
}
template <typename Tuple, std::size_t... I>
void read_tuple_impl(std::istream& is, Tuple& t, std::index_sequence<I...>) {
(..., (is >> std::get<I>(t)));
}
template <typename... Args>
std::istream& operator>>(std::istream& is, std::tuple<Args...>& t) {
read_tuple_impl(is, t, std::index_sequence_for<Args...>{});
return is;
}
template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& v) {
for (auto& elem : v) {
is >> elem;
}
return is;
}
template <typename T>
struct is_pair : std::false_type {};
template <typename T1, typename T2>
struct is_pair<std::pair<T1, T2>> : std::true_type {};
template <typename T>
struct is_tuple : std::false_type {};
template <typename... Args>
struct is_tuple<std::tuple<Args...>> : std::true_type {};
template <typename T>
struct is_vector : std::false_type {};
template <typename T>
struct is_vector<std::vector<T>> : std::true_type {};
template <typename T>
void adjust_zero_indexed(T& val) {
using DecayedT = std::decay_t<T>;
if constexpr (is_pair<DecayedT>::value) {
adjust_zero_indexed(val.first);
adjust_zero_indexed(val.second);
} else if constexpr (is_tuple<DecayedT>::value) {
std::apply([](auto&... args) { (adjust_zero_indexed(args), ...); }, val);
} else if constexpr (is_vector<DecayedT>::value) {
for (auto& elem : val) {
adjust_zero_indexed(elem);
}
} else if constexpr (std::is_arithmetic_v<DecayedT> &&
!std::is_same_v<DecayedT, char> &&
!std::is_same_v<DecayedT, signed char> &&
!std::is_same_v<DecayedT, unsigned char> &&
!std::is_same_v<DecayedT, wchar_t> &&
#if defined(__cpp_char8_t)
!std::is_same_v<DecayedT, char8_t> &&
#endif
!std::is_same_v<DecayedT, char16_t> &&
!std::is_same_v<DecayedT, char32_t> &&
!std::is_same_v<DecayedT, bool>) {
--val;
} else {
}
}
using default_type = long;
template <typename... Args>
void read(Args&... args) {
(std::cin >> ... >> args);
}
template <typename T = default_type>
T read_val() {
T val;
std::cin >> val;
return val;
}
template <typename T1 = default_type, typename T2 = default_type>
std::pair<T1, T2> read_pair() {
std::pair<T1, T2> p;
std::cin >> p;
return p;
}
template <typename... Args>
std::tuple<Args...> read_tuple() {
std::tuple<Args...> t;
std::cin >> t;
return t;
}
template <typename T = default_type, typename Size, std::enable_if_t<std::is_integral_v<Size> && !std::is_same_v<Size, bool>, int> = 0>
std::vector<T> read_vec(Size n, bool zero_indexed = false) {
std::vector<T> v(n);
std::cin >> v;
if (zero_indexed) {
adjust_zero_indexed(v);
}
return v;
}
template <typename T = default_type>
std::vector<T> read_vec(bool zero_indexed = false) {
int n;
std::cin >> n;
return read_vec<T>(n, zero_indexed);
}
template <typename T1 = default_type, typename T2 = default_type, typename Size, std::enable_if_t<std::is_integral_v<Size> && !std::is_same_v<Size, bool>, int> = 0>
std::vector<std::pair<T1, T2>> read_vec_pair(Size n, bool zero_indexed = false) {
return read_vec<std::pair<T1, T2>>(n, zero_indexed);
}
template <typename T1 = default_type, typename T2 = default_type>
std::vector<std::pair<T1, T2>> read_vec_pair(bool zero_indexed = false) {
int n;
std::cin >> n;
return read_vec_pair<T1, T2>(n, zero_indexed);
}
template <typename... Args, typename Size, std::enable_if_t<std::is_integral_v<Size> && !std::is_same_v<Size, bool>, int> = 0>
std::vector<std::tuple<Args...>> read_vec_tuple(Size n, bool zero_indexed = false) {
return read_vec<std::tuple<Args...>>(n, zero_indexed);
}
template <typename... Args>
std::vector<std::tuple<Args...>> read_vec_tuple(bool zero_indexed = false) {
int n;
std::cin >> n;
return read_vec_tuple<Args...>(n, zero_indexed);
}
template <typename T = default_type>
std::vector<std::vector<T>> read_vec_grid(int h, int w, bool zero_indexed = false) {
std::vector<std::vector<T>> grid(h, std::vector<T>(w));
std::cin >> grid;
if (zero_indexed) {
adjust_zero_indexed(grid);
}
return grid;
}
template <typename T = default_type>
std::vector<std::vector<T>> read_vec_grid(bool zero_indexed = false) {
int h, w;
std::cin >> h >> w;
return read_vec_grid<T>(h, w, zero_indexed);
}
template <typename T = default_type, typename Size, std::enable_if_t<std::is_integral_v<Size> && !std::is_same_v<Size, bool>, int> = 0>
std::vector<std::vector<T>> read_vec_var(Size n, bool zero_indexed = false) {
std::vector<std::vector<T>> res(n);
for (int i = 0; i < static_cast<int>(n); ++i) {
int m;
std::cin >> m;
res[i] = read_vec<T>(m, zero_indexed);
}
return res;
}
template <typename T = default_type>
std::vector<std::vector<T>> read_vec_var(bool zero_indexed = false) {
int n;
std::cin >> n;
return read_vec_var<T>(n, zero_indexed);
}
template <typename T = default_type>
T read_zero_idx() {
T val;
std::cin >> val;
adjust_zero_indexed(val);
return val;
}
inline std::vector<std::vector<int>> read_graph(int n, int m, bool directed = false) {
std::vector<std::vector<int>> g(n);
for (int i = 0; i < m; ++i) {
int u = read_zero_idx<int>();
int v = read_zero_idx<int>();
g[u].push_back(v);
if (!directed) {
g[v].push_back(u);
}
}
return g;
}
inline std::vector<std::vector<int>> read_graph(bool directed = false) {
int n, m;
std::cin >> n >> m;
return read_graph(n, m, directed);
}
#include <istream>
#include <numeric>
#include <print>
#include <vector>
#define ALL(a) (a).begin(), (a).end()
using i128 = __int128;
template <typename T, typename U>
inline bool chmin(T& a, const U& b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template <typename T, typename U>
inline bool chmax(T& a, const U& b) {
if (a < b) {
a = b;
return true;
}
return false;
}
template <std::integral T>
inline T div_ceil(T a, T b) {
if (a > 0) return a / b + (a % b != 0);
return a / b;
}
template <std::integral T>
inline T div_floor(T a, T b) {
if (a < 0) return a / b - (a % b != 0);
return a / b;
}
template <std::integral T>
inline T mod(T a, T m) {
a %= m;
if (a < 0) a += m;
return a;
}
template <typename T>
inline constexpr T INF = std::numeric_limits<T>::max() / 2;
template <>
inline constexpr float INF<float> = std::numeric_limits<float>::infinity();
template <>
inline constexpr double INF<double> = std::numeric_limits<double>::infinity();
template <>
inline constexpr long double INF<long double> = std::numeric_limits<long double>::infinity();
template <typename T = int>
inline std::vector<T> iota_vec(int n, T start = 0) {
std::vector<T> v(n);
std::iota(v.begin(), v.end(), start);
return v;
}
template <typename T>
inline std::vector<T> doubled_vec(const std::vector<T>& v) {
std::vector<T> res;
res.reserve(v.size() * 2);
res.insert(res.end(), v.begin(), v.end());
res.insert(res.end(), v.begin(), v.end());
return res;
}
inline void Yes(bool b = true) {
std::println("{}", (b ? "Yes" : "No"));
}
inline void No() {
std::println("No");
}
#ifdef LOCAL
#include <utility/debug.hpp>
#else
#define debug(...)
#endif
#include <algorithm>
#include <cassert>
#include <cstddef>
#include <functional>
#include <iostream>
#include <limits>
#include <numeric>
#include <stdexcept>
#include <vector>
template <typename T, typename Op = std::function<T(const T&, const T&)>>
struct SWAG {
private:
struct Node {
T val;
T acc;
};
std::vector<Node> front, back;
Op op;
T identity;
public:
using size_type = std::size_t;
SWAG(Op op_, T identity_) : op(op_), identity(identity_) {
}
inline T all_prod() const {
if (empty()) return identity;
if (front.empty()) return back.back().acc;
if (back.empty()) return front.back().acc;
return op(front.back().acc, back.back().acc);
}
inline size_type size() const {
return front.size() + back.size();
}
inline bool empty() const {
return front.empty() && back.empty();
}
void push(const T& x) {
if (back.empty()) {
back.push_back({x, x});
} else {
back.push_back({x, op(back.back().acc, x)});
}
}
void pop() {
assert(!empty());
if (empty()) return;
if (front.empty()) {
while (!back.empty()) {
T v = back.back().val;
back.pop_back();
T acc = (front.empty()) ? v : op(v, front.back().acc);
front.push_back({v, acc});
}
}
front.pop_back();
}
const T& front_element() const {
assert(!empty());
if (empty()) throw std::out_of_range("SWAG::front_element called on empty queue");
if (front.empty()) {
return back.front().val;
}
return front.back().val;
}
void clear() {
front.clear();
back.clear();
}
};
template <typename T, typename Op>
inline SWAG<T, Op> make_swag(Op op, T identity) {
return SWAG<T, Op>(op, identity);
}
template <typename T>
inline auto make_min_swag(T inf = std::numeric_limits<T>::max()) {
auto op = [](const T& a, const T& b) { return std::min(a, b); };
return SWAG<T, decltype(op)>(op, inf);
}
template <typename T>
inline auto make_max_swag(T minf = std::numeric_limits<T>::lowest()) {
auto op = [](const T& a, const T& b) { return std::max(a, b); };
return SWAG<T, decltype(op)>(op, minf);
}
template <typename T>
inline auto make_sum_swag(T zero = T{}) {
auto op = std::plus<T>{};
return SWAG<T, decltype(op)>(op, zero);
}
template <typename T>
inline auto make_gcd_swag() {
auto op = [](const T& a, const T& b) { return std::gcd(a, b); };
return SWAG<T, decltype(op)>(op, T{0});
}
void solve() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int N, M;
read(N, M);
auto A = read_vec(N);
auto B = read_vec(N);
auto swag = make_sum_swag(0L);
long ans = 0;
for (auto [a, b] : ranges::views::zip(A, B)) {
long cur = a - b >= 0 ? a - b : 0;
swag.push(cur);
if (ssize(swag) > M) swag.pop();
if (ssize(swag) <= M) chmax(ans, swag.all_prod());
}
println("{}", ans);
}
int main() {
solve();
}
秋ナス🍆