結果

問題 No.3681 心の沸騰石
コンテスト
ユーザー norioc
提出日時 2026-09-05 15:12:17
言語 Rust
(1.97.1 + proconio + num + itertools)
コンパイル:
/usr/bin/rustc_custom
実行:
./target/release/main
結果
AC  
実行時間 0 ms / 2,000 ms
+ 775µs
コード長 1,361 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 2,019 ms
コンパイル使用メモリ 186,848 KB
実行使用メモリ 9,788 KB
最終ジャッジ日時 2026-09-05 15:12:25
合計ジャッジ時間 3,794 ms
ジャッジサーバーID
(参考情報)
judge1_0 / judge4_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 4
other AC * 13
権限があれば一括ダウンロードができます

ソースコード

diff #
raw source code

#![allow(non_snake_case, unused_imports)]

use std::cmp::Reverse;
use std::collections::{BinaryHeap, HashMap, HashSet};
use proconio::{input, marker::Usize1, marker::Chars};
use itertools::Itertools;

#[allow(unused_macros)]
macro_rules! d {
    ( $( $x:expr ),* $(,)? ) => {
        eprintln!(
            concat!( $( stringify!($x), "={:?} " ),* ),
            $( $x ),*
        );
    };
}

#[allow(dead_code)]
fn yn(b: bool) -> &'static str {
    if b { "Yes" } else { "No" }
}

fn bsearch<F>(low: i64, high: i64, pred: F) -> i64
where
    F: Fn(i64) -> bool,
{
    assert!(pred(low));

    let mut lo = low;
    let mut hi = high;
    let mut res = low;
    while lo <= hi {
        let m = lo.midpoint(hi);
        if pred(m) {
            res = res.max(m);
            lo = m + 1;
        } else {
            hi = m - 1;
        }
    }

    res
}

fn main() {
    input! {
        R: i64,P: i64,Q: i64,
        A: i64,B: i64,C: i64,D: i64,
    }

    // m 人作れるか
    let can = |m: i64| -> bool {
        let lack = (m - A).max(0) + (m - B).max(0) + (m - C).max(0);
        let surplus = (A - m).max(0) + (B - m).max(0) + (C - m).max(0) + D;

        if lack > surplus {
            return false;
        }

        let cost = m * P + lack * Q;
        R >= cost
    };

    let ans = bsearch(0, 10_i64.pow(9), can);
    println!("{}", ans);
}
0