結果

問題 No.2694 The Early Bird Catches The Worm
ユーザー ikomaikoma
提出日時 2024-03-22 22:19:30
言語 Rust
(1.77.0)
結果
AC  
実行時間 95 ms / 2,000 ms
コード長 3,875 bytes
コンパイル時間 1,244 ms
コンパイル使用メモリ 193,652 KB
実行使用メモリ 9,856 KB
最終ジャッジ日時 2024-03-22 22:20:10
合計ジャッジ時間 7,170 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,548 KB
testcase_01 AC 1 ms
6,548 KB
testcase_02 AC 1 ms
6,548 KB
testcase_03 AC 1 ms
6,548 KB
testcase_04 AC 1 ms
6,548 KB
testcase_05 AC 1 ms
6,548 KB
testcase_06 AC 2 ms
6,548 KB
testcase_07 AC 1 ms
6,548 KB
testcase_08 AC 2 ms
6,548 KB
testcase_09 AC 1 ms
6,548 KB
testcase_10 AC 1 ms
6,548 KB
testcase_11 AC 1 ms
6,548 KB
testcase_12 AC 1 ms
6,548 KB
testcase_13 AC 1 ms
6,548 KB
testcase_14 AC 1 ms
6,548 KB
testcase_15 AC 1 ms
6,548 KB
testcase_16 AC 1 ms
6,548 KB
testcase_17 AC 1 ms
6,548 KB
testcase_18 AC 1 ms
6,548 KB
testcase_19 AC 1 ms
6,548 KB
testcase_20 AC 2 ms
6,548 KB
testcase_21 AC 1 ms
6,548 KB
testcase_22 AC 1 ms
6,548 KB
testcase_23 AC 1 ms
6,548 KB
testcase_24 AC 25 ms
6,548 KB
testcase_25 AC 23 ms
6,548 KB
testcase_26 AC 29 ms
6,548 KB
testcase_27 AC 39 ms
6,548 KB
testcase_28 AC 44 ms
6,548 KB
testcase_29 AC 15 ms
6,548 KB
testcase_30 AC 70 ms
8,064 KB
testcase_31 AC 40 ms
6,548 KB
testcase_32 AC 74 ms
8,320 KB
testcase_33 AC 72 ms
8,192 KB
testcase_34 AC 4 ms
6,548 KB
testcase_35 AC 39 ms
6,548 KB
testcase_36 AC 48 ms
6,548 KB
testcase_37 AC 81 ms
8,960 KB
testcase_38 AC 55 ms
6,548 KB
testcase_39 AC 13 ms
6,548 KB
testcase_40 AC 40 ms
6,548 KB
testcase_41 AC 19 ms
6,548 KB
testcase_42 AC 2 ms
6,548 KB
testcase_43 AC 7 ms
6,548 KB
testcase_44 AC 82 ms
8,960 KB
testcase_45 AC 83 ms
8,960 KB
testcase_46 AC 24 ms
6,548 KB
testcase_47 AC 26 ms
6,548 KB
testcase_48 AC 44 ms
6,548 KB
testcase_49 AC 49 ms
9,856 KB
testcase_50 AC 50 ms
9,856 KB
testcase_51 AC 50 ms
9,856 KB
testcase_52 AC 49 ms
9,856 KB
testcase_53 AC 49 ms
9,856 KB
testcase_54 AC 94 ms
9,856 KB
testcase_55 AC 91 ms
9,856 KB
testcase_56 AC 91 ms
9,856 KB
testcase_57 AC 91 ms
9,856 KB
testcase_58 AC 90 ms
9,856 KB
testcase_59 AC 91 ms
9,856 KB
testcase_60 AC 91 ms
9,856 KB
testcase_61 AC 90 ms
9,856 KB
testcase_62 AC 91 ms
9,856 KB
testcase_63 AC 91 ms
9,856 KB
testcase_64 AC 90 ms
9,856 KB
testcase_65 AC 90 ms
9,856 KB
testcase_66 AC 95 ms
9,856 KB
testcase_67 AC 91 ms
9,856 KB
testcase_68 AC 90 ms
9,856 KB
testcase_69 AC 72 ms
9,856 KB
testcase_70 AC 70 ms
9,856 KB
testcase_71 AC 71 ms
9,856 KB
testcase_72 AC 70 ms
9,856 KB
testcase_73 AC 69 ms
9,856 KB
testcase_74 AC 35 ms
6,548 KB
testcase_75 AC 70 ms
9,856 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

#![allow(unused_imports, dead_code, unused_macros, unused_variables, non_snake_case, unused_parens)]
use std::cmp::*;
use std::mem::swap;
use std::collections::*;

const MOD:u64 = 1_000_000_007;
const INF:i64 = 0x7fff_ffff_ffff_ffff;

macro_rules! min {($a:expr $(,)*) => {{$a}};($a:expr, $b:expr $(,)*) => {{std::cmp::min($a, $b)}};($a:expr, $($rest:expr),+ $(,)*) => {{std::cmp::min($a, min!($($rest),+))}};}
macro_rules! max {($a:expr $(,)*) => {{$a}};($a:expr, $b:expr $(,)*) => {{std::cmp::max($a, $b)}};($a:expr, $($rest:expr),+ $(,)*) => {{std::cmp::max($a, max!($($rest),+))}};}
macro_rules! chmin {($base:expr, $($cmps:expr),+ $(,)*) => {{let cmp_min = min!($($cmps),+);if $base > cmp_min {$base = cmp_min;true} else {false}}};}
macro_rules! chmax {($base:expr, $($cmps:expr),+ $(,)*) => {{let cmp_max = max!($($cmps),+);if $base < cmp_max {$base = cmp_max;true} else {false}}};}
macro_rules! mulvec {($x:expr; $s:expr) => {vec![$x; $s]};($x:expr; $s0:expr; $( $s:expr );+) => {mulvec![vec![$x; $s0]; $( $s );+ ]};}
macro_rules! outputln {($var:expr)=>{println!("{}",$var)};($var:expr,$($vars:expr),+)=>{print!("{} ",$var);outputln!($($vars),+);};}
macro_rules! debug {($($a:expr),* $(,)*) => {eprintln!(concat!($("| ",stringify!($a), "={:?} "),*, "|"),$(&$a),*);};}


fn solve() {
    input! {
        n: usize,
        H: usize,
		A:[usize;n],
		B:[usize;n],
    }
	let mut a_cumsum = vec![0];
	let mut a_sum = 0;
	for &a in &A {
		a_sum += a;
		a_cumsum.push(a_sum);
	}
	let mut b_cumsum = vec![0];
	let mut b_sum = 0;
	let mut b_cumsum2 = vec![0];
	let mut b_sum2 = 0;
	for (i, &b) in B.iter().enumerate() {
		b_sum += b;
		b_sum2 += b * (i+1);
		b_cumsum.push(b_sum);
		b_cumsum2.push(b_sum2);
	}
    let mut ans = 0;
	for l in 0..n {
		let (mut r0, mut r1) = (l, n+1);
		while r0+1 < r1 {
			let m = (r0+r1)/2;
			let h = b_cumsum2[m] - b_cumsum2[l] - (b_cumsum[m] - b_cumsum[l])*l;
			if h <= H {
				r0 = m;
			}else{
				r1 = m;
			}
		}
		chmax!(ans, a_cumsum[r0] - a_cumsum[l]);
	}
	
    println!("{}", ans);
}

fn main() {
    std::thread::Builder::new()
        .stack_size(128 * 1024 * 1024)
        .spawn(|| solve()).unwrap()
        .join().unwrap();
}


mod _input {
    // https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
    #[macro_export]
    macro_rules! input {
        (source = $s:expr, $($r:tt)*) => {
            let mut iter = $s.split_whitespace();
            let mut next = || { iter.next().unwrap() };
            input_inner!{next, $($r)*}
        };
        ($($r:tt)*) => {
            let stdin = std::io::stdin();
            let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
            let mut next = move || -> String{
                bytes
                    .by_ref()
                    .map(|r|r.unwrap() as char)
                    .skip_while(|c|c.is_whitespace())
                    .take_while(|c|!c.is_whitespace())
                    .collect()
            };
            input_inner!{next, $($r)*}
        };
    }
    #[macro_export]
    macro_rules! input_inner {
        ($next:expr) => {};
        ($next:expr, ) => {};

        ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
            let $var = read_value!($next, $t);
            input_inner!{$next $($r)*}
        };
    }
    #[macro_export]
    macro_rules! read_value {
        ($next:expr, ( $($t:tt),* )) => {
            ( $(read_value!($next, $t)),* )
        };

        ($next:expr, [ $t:tt ; $len:expr ]) => {
            (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        };

        ($next:expr, chars) => {
            read_value!($next, String).chars().collect::<Vec<char>>()
        };

        ($next:expr, usize1) => {
            read_value!($next, usize) - 1
        };

        ($next:expr, $t:ty) => {
            $next().parse::<$t>().expect("Parse error")
        };
    }
}


0