#![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(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); }