fn main() { let ref mut buf = String::new(); std::io::Read::read_to_string(&mut std::io::stdin(), buf).ok(); let mut iter = buf.split_whitespace(); macro_rules! scan { ([$t:tt; $n:expr]) => ((0..$n).map(|_| scan!($t)).collect::>()); (($($t:tt),*)) => (($(scan!($t)),*)); (Usize1) => (scan!(usize) - 1); (Bytes) => (scan!(String).into_bytes()); ($t:ty) => (iter.next().unwrap().parse::<$t>().unwrap()); } let (n, c) = scan!((usize, usize)); let mut items = scan!([i32; n]); items.sort_by(|a, b| b.cmp(a)); let mut coupons = vec![vec![]; 2]; for _ in 0..c { let (t, x) = scan!((Usize1, i32)); coupons[t].push(x); } for coupon in coupons.iter_mut() { (*coupon).sort_by(|a, b| b.cmp(a)); } let len1 = coupons[0].len(); let len2 = coupons[1].len(); let mut dp = vec![1 << 30; n + 1]; dp[0] = 0; let mut sum = 0; for (i, p) in items.into_iter().enumerate() { if i >= c { sum += p; continue; } for c1 in (0..=i.min(len1)).rev() { let c2 = i - c1; if c2 > len2 { break; } let now = dp[c1]; if c1 < len1 { let next = now + (p - coupons[0][c1]).max(0); let value = &mut dp[c1 + 1]; *value = (*value).min(next); } if c2 < len2 { let next = now + p / 100 * (100 - coupons[1][c2]); dp[c1] = next; } } } let ans = dp.iter().min().unwrap() + sum; println!("{}", ans); }