From 6d6705e08e56d60ac846cce245d15016700e5b80 Mon Sep 17 00:00:00 2001 From: koba-e964 <3303362+koba-e964@users.noreply.github.com> Date: Fri, 8 Nov 2024 17:41:38 +0900 Subject: [PATCH] Add atcoder/abc362/c.rs atcoder/abc362/remain.txt --- atcoder/abc362/c.rs | 65 +++++++++++++++++++++++++++++++++++++++ atcoder/abc362/remain.txt | 6 ++++ 2 files changed, 71 insertions(+) create mode 100644 atcoder/abc362/c.rs create mode 100644 atcoder/abc362/remain.txt diff --git a/atcoder/abc362/c.rs b/atcoder/abc362/c.rs new file mode 100644 index 00000000..cb8507ed --- /dev/null +++ b/atcoder/abc362/c.rs @@ -0,0 +1,65 @@ +use std::io::{Write, BufWriter}; +// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 +macro_rules! input { + ($($r:tt)*) => { + let stdin = std::io::stdin(); + let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); + let mut next = move || -> String{ + bytes.by_ref().map(|r|r.unwrap() as char) + .skip_while(|c|c.is_whitespace()) + .take_while(|c|!c.is_whitespace()) + .collect() + }; + input_inner!{next, $($r)*} + }; +} + +macro_rules! input_inner { + ($next:expr) => {}; + ($next:expr,) => {}; + ($next:expr, $var:ident : $t:tt $($r:tt)*) => { + let $var = read_value!($next, $t); + input_inner!{$next $($r)*} + }; +} + +macro_rules! read_value { + ($next:expr, ( $($t:tt),* )) => { ($(read_value!($next, $t)),*) }; + ($next:expr, [ $t:tt ; $len:expr ]) => { + (0..$len).map(|_| read_value!($next, $t)).collect::>() + }; + ($next:expr, $t:ty) => ($next().parse::<$t>().expect("Parse error")); +} + +fn main() { + let out = std::io::stdout(); + let mut out = BufWriter::new(out.lock()); + macro_rules! puts {($($format:tt)*) => (let _ = write!(out,$($format)*););} + macro_rules! putvec { + ($v:expr) => { + for i in 0..$v.len() { + puts!("{}{}", $v[i], if i + 1 == $v.len() {"\n"} else {" "}); + } + } + } + input! { + n: usize, + lr: [(i64, i64); n], + } + let lsum: i64 = lr.iter().map(|&(l, _)| l).sum(); + let rsum: i64 = lr.iter().map(|&(_, r)| r).sum(); + if 0 < lsum || rsum < 0 { + puts!("No\n"); + return; + } + puts!("Yes\n"); + let mut rest = -lsum; + let mut x = vec![0; n]; + for i in 0..n { + let (l, r) = lr[i]; + let mut val = min(rest, r - l); + x[i] = val + l; + rest -= val; + } + putvec!(x); +} diff --git a/atcoder/abc362/remain.txt b/atcoder/abc362/remain.txt new file mode 100644 index 00000000..e3ec3688 --- /dev/null +++ b/atcoder/abc362/remain.txt @@ -0,0 +1,6 @@ +a +b +d +e +f +g