use proconio::input; use std::collections::BTreeSet; use proconio::marker::Usize1; fn main() { input! { n: usize, t: usize, a: [usize; n - 1], k: usize, x: [Usize1; k] } let x: BTreeSet<_> = x.into_iter().collect(); if !ok(k, t, &a, &x) { println!("-1"); return; } let mut l = -1; let mut r = k as isize; while l + 1 < r { let m = (l + r) as usize / 2; if ok(m, t, &a, &x) { r = m as isize; } else { l = m as isize; } } println!("{}", r); } fn ok(mut m:usize, t:usize, a:&Vec, x:&BTreeSet) -> bool { let mut now = t; let mut res = true; for i in 0..a.len() { res &= now > a[i]; if !res { break } now -= a[i]; if x.contains(&i) && m > 0 { now += 10; m -= 1; } } res }