diff --git a/storage/cf/rs/round-1087-A.rs b/storage/cf/rs/round-1087-A.rs new file mode 100644 index 0000000..09b8347 --- /dev/null +++ b/storage/cf/rs/round-1087-A.rs @@ -0,0 +1,42 @@ +use std::io::{read_to_string, stdin}; + +fn main() { + let temp = read_to_string(stdin()).unwrap(); + let mut iter = temp + .split_ascii_whitespace() + .map(|x| x.parse::().unwrap()); + + let t = iter.next().unwrap(); + (0..t).for_each(|_| { + let (n, mut c, mut k) = ( + // number, combat power, k of flip flop + iter.next().unwrap(), + iter.next().unwrap(), + iter.next().unwrap(), + ); + + let mut arr = (0..n).map(|_| iter.next().unwrap()).collect::>(); + arr.sort(); + loop { + let key = arr.binary_search(&c); + match key { + Ok(idx) => { + c += arr[idx]; + arr.remove(idx); + } + Err(idx) => { + if idx == 0 { + break; + } else { + let delta = c - arr[idx - 1]; + let consume = if k >= delta { delta } else { k }; + k -= consume; + c += consume + arr[idx - 1]; + arr.remove(idx - 1); + } + } + } + } + println!("{}", c); + }); +} diff --git a/storage/cf/rs/round-1087-B.rs b/storage/cf/rs/round-1087-B.rs new file mode 100644 index 0000000..145af8b --- /dev/null +++ b/storage/cf/rs/round-1087-B.rs @@ -0,0 +1,37 @@ +use std::io::{read_to_string, stdin}; + +fn main() { + let temp = read_to_string(stdin()).unwrap(); + let mut iter = temp + .split_ascii_whitespace() + .map(|x| x.parse::().unwrap()); + + let t = iter.next().unwrap(); + (0..t).for_each(|_| { + let n = iter.next().unwrap() as usize; + let arr = (0..n).map(|_| iter.next().unwrap()).collect::>(); + + // if n == 1 return 0 + for i in 0..n { + if i == n - 1 { + print!("{} ", 0); + continue; + } + + let key = arr[i]; + + let mut cnt_lo = 0; + let mut cnt_hi = 0; + + for &e in arr[(i + 1)..n].iter() { + if e > key { + cnt_hi += 1; + } else if e < key { + cnt_lo += 1; + } + } + print!("{} ", std::cmp::max(cnt_lo, cnt_hi)); + } + println!(); + }); +} diff --git a/storage/cf/rs/round-1087-C.rs b/storage/cf/rs/round-1087-C.rs new file mode 100644 index 0000000..c09e1e2 --- /dev/null +++ b/storage/cf/rs/round-1087-C.rs @@ -0,0 +1,54 @@ +use std::io::{Write, stdin, stdout}; + +fn client(n: usize) { + let mut line = String::new(); + for i in 0..n - 1 { + let left = 2 * i + 1; + let right = 2 * i + 2; + + println!("? {} {}", left, right); + stdout().flush().unwrap(); + line.clear(); + stdin().read_line(&mut line).unwrap(); + let q = line.trim().parse::().unwrap(); + if q == 1 { + println!("! {}", left); + stdout().flush().unwrap(); + return; + } + } + + println!("? {} {}", 2 * n - 1, 2 * n - 2); + stdout().flush().unwrap(); + line.clear(); + stdin().read_line(&mut line).unwrap(); + let q = line.trim().parse::().unwrap(); + if q == 1 { + println!("! {}", 2 * n - 1); + stdout().flush().unwrap(); + return; + } + println!("? {} {}", 2 * n - 1, 2 * n - 3); + stdout().flush().unwrap(); + line.clear(); + stdin().read_line(&mut line).unwrap(); + let q = line.trim().parse::().unwrap(); + if q == 1 { + println!("! {}", 2 * n - 1); + stdout().flush().unwrap(); + return; + } + println!("! {}", 2 * n); +} + +fn main() { + let mut line = String::new(); + stdin().read_line(&mut line).unwrap(); + let t = line.trim().parse::().unwrap(); + (0..t).for_each(|_| { + line.clear(); + stdin().read_line(&mut line).unwrap(); + let n = line.trim().parse::().unwrap(); + client(n); + }); +}