結果

問題 No.3684 chokudai_niku.png
コンテスト
ユーザー SkyLake
提出日時 2026-09-07 23:04:40
言語 C++23
(gcc 15.3.0 + boost 1.92.0 + ACL)
コンパイル:
g++-15 -O2 -lm -std=c++23 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
AC  
実行時間 22 ms / 2,000 ms
+ 283µs
コード長 6,907 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,122 ms
コンパイル使用メモリ 334,184 KB
実行使用メモリ 8,448 KB
最終ジャッジ日時 2026-09-07 23:04:48
合計ジャッジ時間 7,950 ms
ジャッジサーバーID
(参考情報)
judge2_1 / judge1_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 44
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#include <bits/stdc++.h>
// https://github.com/SkyLake-git/CompeteLib
template<typename T>
concept Arithmetic = std::is_arithmetic_v<T>;
template<typename T>
concept FloatingPoint = std::is_floating_point_v<T>;
template<typename T>
concept GraphLike = requires(T &a)
{
    { a.get_next() } -> std::convertible_to<std::vector<int>>;
    a.get_next(std::declval<int>());
};
template<typename T>
concept GridLike = requires(T &a)
{
    { a[std::declval<size_t>()] };
    sizeof(a);
};
enum DistanceAlgo {
    Euclidean,
    Manhattan
};
template<typename T>
concept DataContainer = requires
                        {
                            typename T::value_type;
                        } &&
                        (std::is_same_v<T, std::queue<typename T::value_type>> ||
                         std::is_same_v<T, std::stack<typename T::value_type>> ||
                         std::is_same_v<T, std::priority_queue<typename T::value_type>>);
template<DataContainer T>
void push_to_data_container(T &container, typename T::value_type v) {
    container.push(v);
}
template<DataContainer T>
T::value_type peek_from_data_container(T &container) {
    if constexpr (std::is_same_v<T, std::queue<typename T::value_type>>) {
        return container.front();
    } else if constexpr (std::is_same_v<T, std::stack<typename T::value_type>>) {
        return container.top();
    } else if constexpr (std::is_same_v<T, std::priority_queue<typename T::value_type>>) {
        return container.top();
    }
    throw std::runtime_error("unexpected type of data container");
}
template<DataContainer T>
void pop_from_data_container(T &container) {
    container.pop();
}
template<Arithmetic T>
T factorial(T a) {
    T res = 1;
    for (T i = a; i > 0; --i) {
        res *= i;
    }
    return res;
}
template<Arithmetic T>
T factorial_mod(T a, T mod) {
    T res = 1;
    for (T i = a; i > 0; --i) {
        res *= i;
        res %= mod;
    }
    return res;
}
template<Arithmetic T>
T probability(T a, T c) {
    T res = a;
    for (int i = 0; i < c; ++i) {
        res *= a - i;
    }
    return res;
}
// 繰り返し2乗法
template<Arithmetic R, Arithmetic T>
R pow_int(T a, T exponent) {
    R x = 1;
    while (exponent > 0) {
        if (exponent % 2 == 1) {
            x *= a;
        }
        a *= a;
        exponent >>= 1;
    }
    return x;
}
template<Arithmetic T>
T ceil_div(T a, T b) {
    if (b < 0)
        a *= -1, b *= -1;
    if (a <= 0)
        return a / b;
    return (a - 1) / b + 1;
}
template<Arithmetic T>
bool is_inside_bounds(T x, T y, T width, T height) {
    return x >= 0 && y >= 0 && x < width && y < height;
}
inline long long ceil_ll(const long double a) {
    return static_cast<long long>(std::ceill(a));
}
inline long long floor_ll(const long double a) {
    return static_cast<long long>(std::floorl(a));
}
template<typename T1, typename T2, typename T3>
struct triplet {
    T1 first{};
    T2 second{};
    T3 third{};
    triplet() = default;
    triplet(T1 first, T2 second, T3 third) {
        this->first = first;
        this->second = second;
        this->third = third;
    }
    auto operator<=>(const triplet &) const = default;
    struct less_second {
        bool operator()(triplet &a, triplet &b) {
            return a.second < b.second;
        }
    };
    struct greater_second {
        bool operator()(triplet &a, triplet &b) {
            return a.second > b.second;
        }
    };
    struct less_third {
        bool operator()(triplet &a, triplet &b) {
            return a.third < b.third;
        }
    };
    struct greater_third {
        bool operator()(triplet &a, triplet &b) {
            return a.third > b.third;
        }
    };
};
template<typename T1, typename T2, typename T3, typename T4>
struct quadruplet {
    T1 first{};
    T2 second{};
    T3 third{};
    T4 fourth{};
    quadruplet() = default;
    quadruplet(T1 first, T2 second, T3 third, T4 fourth) {
        this->first = first;
        this->second = second;
        this->third = third;
        this->fourth = fourth;
    }
    auto operator<=>(const quadruplet &) const = default;
};
template<Arithmetic T>
void debug_arr(auto arr, const T size) {
}
static std::mt19937_64 rnd_mt64(100);
namespace timer {
    static std::chrono::time_point<std::chrono::steady_clock> start_time = std::chrono::steady_clock::now();
    inline long long elapsed_ms() {
        return std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::steady_clock::now() - start_time).
                count();
    }
    inline void reset() {
        start_time = std::chrono::steady_clock::now();
    }
}
inline unsigned long long randl_range(unsigned long long min_val, unsigned long long max_val) {
    std::uniform_int_distribution get_rand_uni_int(min_val, max_val);
    return get_rand_uni_int(rnd_mt64);
}
inline unsigned int randi_range(unsigned int min_val, unsigned int max_val) {
    std::uniform_int_distribution get_rand_uni_int(min_val, max_val);
    return get_rand_uni_int(rnd_mt64);
}
inline long double randf() {
    return static_cast<long double>(randl_range(0, std::numeric_limits<unsigned long long>::max())) / std::numeric_limits<unsigned long
               long>::max();
}
inline std::generator<int> range_bfs(int min, int max, int start) {
    co_yield start;
    for (int d = 1; d <= max - min; ++d) {
        int right = start + d;
        int left = start - d;
        if (right <= max)
            co_yield right;
        if (left >= min)
            co_yield left;
    }
}
// (min + max) / 2 から1ずつmin, maxに近づいていく数列を返す
inline std::generator<int> range_mid_bfs(int min, int max) {
    return range_bfs(min, max, (min + max) / 2);
}
template<typename T>
std::ostream &operator<<(std::ostream &os, std::vector<T> arr) {
    std::string s = "[ ";
    for (int i = 0; i < arr.size(); ++i) {
        s.append(std::to_string(arr[i]) + ", ");
    }
    os << s << "]";
    return os;
}
inline void hack_syncio() {
    std::ios_base::sync_with_stdio(false);
    std::cin.tie(nullptr);
}
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using namespace std;
int main() {
    hack_syncio();
    int n, m;
    cin >> n >> m;
    ll a[n];
    ll b[n];
    ll sums[n];
    ll cur_sum = 0;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        cin >> b[i];
        if (a[i] - b[i] > 0) {
            cur_sum += a[i] - b[i];
        }
        sums[i] = cur_sum;
    }
    ll max_iwai_toku_kingaku = 0;
    for (int i = 0; i <= n - m; ++i) {
        ll toku_kingaku = sums[min(i + m - 1, n - 1)] - sums[i];
        if (a[i] - b[i] > 0) {
            toku_kingaku += a[i] - b[i];
        }
        if (toku_kingaku > max_iwai_toku_kingaku) {
            max_iwai_toku_kingaku = toku_kingaku;
        }
    }
    cout << max_iwai_toku_kingaku << endl;
}
0