結果

問題 No.1148 土偶Ⅲ
ユーザー Mister
提出日時 2020-08-05 18:46:57
言語 C++17
(gcc 13.3.0 + boost 1.87.0)
結果
AC  
実行時間 44 ms / 2,000 ms
コード長 685 bytes
コンパイル時間 816 ms
コンパイル使用メモリ 81,716 KB
最終ジャッジ日時 2025-01-12 15:03:40
ジャッジサーバーID
(参考情報)
judge5 / judge4
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 25
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <iostream>
#include <vector>
#include <set>

using lint = long long;

void solve() {
    int n;
    lint w;
    std::cin >> n >> w;

    std::vector<lint> xs(n);
    for (auto& x : xs) std::cin >> x;

    int ans = 0, r = 0;
    lint sum = 0;
    std::set<int> s;

    for (int l = 0; l < n; ++l) {
        while (r < n && sum + xs[r] <= w && !s.count(xs[r])) {
            sum += xs[r];
            s.insert(xs[r]);
            ++r;
        }
        ans = std::max(ans, r - l);

        sum -= xs[l];
        s.erase(xs[l]);
    }

    std::cout << ans << "\n";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    solve();

    return 0;
}
0