Skip to content

Commit

Permalink
Add atcoder/abc362/c.rs atcoder/abc362/remain.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
koba-e964 committed Nov 8, 2024
1 parent ce61405 commit 6d6705e
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 0 deletions.
65 changes: 65 additions & 0 deletions atcoder/abc362/c.rs
Original file line number Diff line number Diff line change
@@ -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::<Vec<_>>()
};
($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);
}
6 changes: 6 additions & 0 deletions atcoder/abc362/remain.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
a
b
d
e
f
g

0 comments on commit 6d6705e

Please sign in to comment.