Educational Codeforces Round 61 B. Discounts


https://codeforces.com/contest/1132/problem/B

I was going to solve all the problems by Rust. But, I lost the motivation due to TLE in the problem B. I rewrite the I/O after the contest, then my solution becomes faster than the C++'s one. I'll try to simplify this code more.

C++: 296ms https://codeforces.com/contest/1132/submission/51064539
Rust: 156 ms https://codeforces.com/contest/1132/submission/51101880


fn main() {
  use std::io::{Read, Write, BufWriter};
  let mut a = Vec::new();
  std::io::stdin().read_to_end(&mut a).unwrap();
  let a = String::from_utf8(a).unwrap();
  let mut a = a.split_whitespace();
  let mut b = BufWriter::new(std::io::stdout());
  macro_rules! yomu { () => (a.next().unwrap().parse().unwrap()) }
  macro_rules! kaku { ($($arg:tt)*) => (writeln!(b, $($arg)*).unwrap()) }
  
  let n: usize = yomu!();
  let mut a: Vec<i64> = Vec::new();
  for _ in 0..n { a.push(yomu!()); }
  let s: i64 = a.iter().sum();
  a.sort();
  let m: usize = yomu!();
  let mut q: Vec<usize> = Vec::new();
  for _ in 0..m { q.push(yomu!()); }
  for q in q {
    kaku!("{}", s - a[n - q]);
  }
}