結果

問題 No.3758 Fan Meeting
コンテスト
ユーザー 39Y Nako
提出日時 2026-10-09 22:48:08
言語 Rust
(1.97.1 + proconio + num + itertools + ACL)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
WA  
実行時間 -
コード長 1,690 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 800 ms
コンパイル使用メモリ 199,124 KB
実行使用メモリ 9,920 KB
最終ジャッジ日時 2026-10-09 22:48:16
合計ジャッジ時間 7,576 ms
ジャッジサーバーID
(参考情報)
judge3_0 / judge5_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 6 WA * 17 TLE * 1 -- * 23
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

use std::collections::VecDeque;

use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        n: usize,
        s: usize,
        mut a: [usize; n],
    }
    a.sort_unstable();
    a.reverse();

    let mut x = s;
    let mut v = VecDeque::new();
    while x > 0 {
        let idx = a.partition_point(|&p| p >= x);
        if idx == n {
            break;
        }

        x -= a[idx] + 1;
        v.push_back((idx, a[idx] + 1, idx));
    }

    for i in 1..v.len() {
        if v[i].0 <= v[i - 1].0 {
            v[i] = (v[i - 1].0 + 1, v[i].1, v[i - 1].0 + 1);
        }
    }

    if v.is_empty() {
        println!("{}", a.iter().sum::<usize>());
        return;
    }

    let mut ans = 0;
    let mut cnt = 0;
    while cnt < n {
        let mut nv = VecDeque::new();
        for _ in 0..v.len() {
            let (idx, x, fidx) = v.pop_front().unwrap();

            if idx >= n {
                continue;
            }

            if a[idx] == 0 {
                continue;
            }

            if x > a[idx] {
                cnt += 1;
                a[idx] = 0;
                if idx + 1 < n {
                    nv.push_back((idx + 1, x, fidx));
                } else if fidx > 0 {
                    nv.push_back((fidx - 1, x, fidx));
                } else {
                    continue;
                }
            } else {
                a[idx] -= 1;

                if a[idx] == 0 {
                    cnt += 1;
                    if idx > 0 {
                        nv.push_back((idx - 1, x, fidx));
                    }
                }
            }
        }

        v = nv;
        ans += 1;
    }

    println!("{}", ans);
}
0