QOJ.ac
QOJ
ID | Problem | Submitter | Result | Time | Memory | Language | File size | Submit time | Judge time |
---|---|---|---|---|---|---|---|---|---|
#679009 | #9529. Farm Management | ucup-team296# | AC ✓ | 45ms | 10816kb | Rust | 40.5kb | 2024-10-26 16:39:36 | 2024-10-26 16:39:37 |
Judging History
answer
// https://contest.ucup.ac/contest/1817/problem/9529
pub mod solution {
//{"name":"K. Farm Management","group":"Universal Cup - The 3rd Universal Cup. Stage 14: Harbin","url":"https://contest.ucup.ac/contest/1817/problem/9529","interactive":false,"timeLimit":1000,"tests":[{"input":"5 17\n2 3 4\n6 1 5\n8 2 4\n4 3 3\n7 5 5\n","output":"109\n"}],"testType":"single","input":{"type":"stdin","fileName":null,"pattern":null},"output":{"type":"stdout","fileName":null,"pattern":null},"languages":{"java":{"taskClass":"KFarmManagement"}}}
use crate::algo_lib::collections::min_max::MinimMaxim;
use crate::algo_lib::collections::segment_tree::SegmentTree;
use crate::algo_lib::collections::segment_tree::SegmentTreeNode;
use crate::algo_lib::collections::vec_ext::sorted::Sorted;
use crate::algo_lib::io::input::Input;
use crate::algo_lib::io::output::Output;
use crate::algo_lib::misc::direction::Direction;
use crate::algo_lib::misc::test_type::TaskType;
use crate::algo_lib::misc::test_type::TestType;
type PreCalc = ();
fn solve(input: &mut Input, out: &mut Output, _test_case: usize, _data: &mut PreCalc) {
let n = input.read_size();
let m = input.read_size();
let jobs = input.read_vec::<(usize, usize, usize)>(n).sorted();
struct Node {
min: usize,
max: usize,
base_profit: usize,
add_profit: usize,
}
impl SegmentTreeNode for Node {
fn new(_left: usize, _right: usize) -> Self {
Node {
min: 0,
max: 0,
base_profit: 0,
add_profit: 0,
}
}
fn join(&mut self, left_val: &Self, right_val: &Self) {
self.min = left_val.min + right_val.min;
self.max = left_val.max + right_val.max;
self.base_profit = left_val.base_profit + right_val.base_profit;
self.add_profit = left_val.add_profit + right_val.add_profit;
}
fn accumulate(&mut self, _value: &Self) {}
fn reset_delta(&mut self) {}
}
let mut ans = 0;
let mut rem = m;
let mut sum_r = 0;
for i in 0..n - 1 {
let (w, l, r) = jobs[i];
ans += w * l;
rem -= l;
sum_r += r;
}
ans += jobs[n - 1].0 * rem;
sum_r += jobs[n - 1].2;
let mut st = SegmentTree::from_generator(n, |i| {
let (w, l, r) = jobs[i];
Node {
min: l,
max: r,
base_profit: w * l,
add_profit: w * (r - l),
}
});
for i in 0..n - 1 {
let x = m.saturating_sub(sum_r - jobs[i].2);
st.point_update(
i,
Node {
min: x,
max: x,
base_profit: x * jobs[i].0,
add_profit: 0,
},
);
let mut left = 0;
let mut right = 0;
let mut res = 0;
let mut rem = m;
let add = st.binary_search(
|l, r| {
let cur_left = left + l.min;
let cur_right = right + r.max;
if cur_left + cur_right > m {
res += l.base_profit;
left += l.min;
rem -= l.min;
Direction::Right
} else {
res += r.base_profit + r.add_profit;
right += r.max;
rem -= r.max;
Direction::Left
}
},
|_, pos| jobs[pos].0,
);
res += add * rem;
ans.maxim(res);
st.point_update(
i,
Node {
min: jobs[i].1,
max: jobs[i].2,
base_profit: jobs[i].0 * jobs[i].1,
add_profit: jobs[i].0 * (jobs[i].2 - jobs[i].1),
},
)
}
out.print_line(ans);
}
pub static TEST_TYPE: TestType = TestType::Single;
pub static TASK_TYPE: TaskType = TaskType::Classic;
pub(crate) fn run(mut input: Input, mut output: Output) -> bool {
let mut pre_calc = ();
match TEST_TYPE {
TestType::Single => solve(&mut input, &mut output, 1, &mut pre_calc),
TestType::MultiNumber => {
let t = input.read();
for i in 1..=t {
solve(&mut input, &mut output, i, &mut pre_calc);
}
}
TestType::MultiEof => {
let mut i = 1;
while input.peek().is_some() {
solve(&mut input, &mut output, i, &mut pre_calc);
i += 1;
}
}
}
output.flush();
match TASK_TYPE {
TaskType::Classic => input.is_empty(),
TaskType::Interactive => true,
}
}
}
pub mod algo_lib {
pub mod collections {
pub mod bounds {
use std::ops::RangeBounds;
pub fn clamp(range: impl RangeBounds<usize>, n: usize) -> (usize, usize) {
let start = match range.start_bound() {
std::ops::Bound::Included(&x) => x,
std::ops::Bound::Excluded(&x) => x + 1,
std::ops::Bound::Unbounded => 0,
};
let end = match range.end_bound() {
std::ops::Bound::Included(&x) => x + 1,
std::ops::Bound::Excluded(&x) => x,
std::ops::Bound::Unbounded => n,
};
(start, end.min(n))
}
}
pub mod min_max {
pub trait MinimMaxim<Rhs = Self>: PartialOrd + Sized {
fn minim(&mut self, other: Rhs) -> bool;
fn maxim(&mut self, other: Rhs) -> bool;
}
impl<T: PartialOrd> MinimMaxim for T {
fn minim(&mut self, other: Self) -> bool {
if other < *self {
*self = other;
true
} else {
false
}
}
fn maxim(&mut self, other: Self) -> bool {
if other > *self {
*self = other;
true
} else {
false
}
}
}
impl<T: PartialOrd> MinimMaxim<T> for Option<T> {
fn minim(&mut self, other: T) -> bool {
match self {
None => {
*self = Some(other);
true
}
Some(v) => v.minim(other),
}
}
fn maxim(&mut self, other: T) -> bool {
match self {
None => {
*self = Some(other);
true
}
Some(v) => v.maxim(other),
}
}
}
}
pub mod segment_tree {
use crate::algo_lib::collections::bounds::clamp;
use crate::algo_lib::misc::direction::Direction;
use crate::algo_lib::numbers::num_traits::algebra::One;
use crate::algo_lib::numbers::num_traits::algebra::Zero;
use crate::when;
use std::marker::PhantomData;
use std::ops::Add;
use std::ops::MulAssign;
use std::ops::RangeBounds;
pub trait SegmentTreeNode {
fn new(left: usize, right: usize) -> Self;
fn join(&mut self, left_val: &Self, right_val: &Self);
fn accumulate(&mut self, value: &Self);
fn reset_delta(&mut self);
}
pub trait Pushable<T>: SegmentTreeNode {
fn push(&mut self, delta: T);
}
impl<T: SegmentTreeNode> Pushable<&T> for T {
fn push(&mut self, delta: &T) {
self.accumulate(delta);
}
}
impl<T: SegmentTreeNode> Pushable<T> for T {
fn push(&mut self, delta: T) {
*self = delta;
}
}
pub trait QueryResult<Result, Args>: SegmentTreeNode {
fn empty_result(args: &Args) -> Result;
fn result(&self, args: &Args) -> Result;
fn join_results(
left_res: Result,
right_res: Result,
args: &Args,
left: usize,
mid: usize,
right: usize,
) -> Result;
}
impl<T: SegmentTreeNode + Clone> QueryResult<T, ()> for T {
fn empty_result(_: &()) -> T {
Self::new(0, 0)
}
fn result(&self, _: &()) -> T {
self.clone()
}
fn join_results(left_res: T, right_res: T, _: &(), left: usize, mid: usize, right: usize) -> T {
when! {
left == mid => right_res,
right == mid => left_res,
else => {
let mut res = Self::new(left, right);
res.join(&left_res, &right_res);
res
},
}
}
}
impl<
Key: Add<Output = Key> + MulAssign<Delta> + Zero + Copy,
Delta: MulAssign<Delta> + One + Copy,
> SegmentTreeNode for (Key, Delta)
{
fn new(_left: usize, _right: usize) -> Self {
(Key::zero(), Delta::one())
}
fn join(&mut self, left_val: &Self, right_val: &Self) {
self.0 = left_val.0 + right_val.0;
}
fn accumulate(&mut self, value: &Self) {
self.0 *= value.1;
self.1 *= value.1;
}
fn reset_delta(&mut self) {
self.1 = Delta::one();
}
}
#[derive(Clone)]
pub struct SegmentTree<Node> {
n: usize,
nodes: Vec<Node>,
}
impl<Node: SegmentTreeNode> SegmentTree<Node> {
pub fn new(n: usize) -> Self {
Self::from_generator(n, |left| Node::new(left, left + 1))
}
pub fn from_array(arr: Vec<Node>) -> Self {
let n = arr.len();
let mut iter = arr.into_iter();
Self::from_generator(n, |_| iter.next().unwrap())
}
pub fn from_generator<F>(n: usize, gen: F) -> Self
where
F: FnMut(usize) -> Node,
{
if n == 0 {
return Self {
n,
nodes: vec![Node::new(0, 0)],
};
}
let mut res = Self {
n,
nodes: Vec::with_capacity(2 * n - 1),
};
res.init(gen);
res
}
fn init<F>(&mut self, mut f: F)
where
F: FnMut(usize) -> Node,
{
self.init_impl(2 * self.n - 2, 0, self.n, &mut f);
}
fn init_impl<F>(&mut self, root: usize, left: usize, right: usize, f: &mut F)
where
F: FnMut(usize) -> Node,
{
if left + 1 == right {
self.nodes.push(f(left));
} else {
let mid = left + ((right - left) >> 1);
let left_child = root - 2 * (right - mid);
let right_child = root - 1;
self.init_impl(left_child, left, mid, f);
self.init_impl(right_child, mid, right, f);
let mut node = Node::new(left, right);
node.join(&self.nodes[left_child], &self.nodes[right_child]);
self.nodes.push(node);
}
}
pub fn point_query(&mut self, at: usize) -> &Node {
assert!(at < self.n);
self.do_point_query(self.nodes.len() - 1, 0, self.n, at)
}
fn do_point_query(&mut self, root: usize, left: usize, right: usize, at: usize) -> &Node {
if left + 1 == right {
&self.nodes[root]
} else {
let mid = (left + right) >> 1;
self.push_down(root, mid, right);
let left_child = root - 2 * (right - mid);
let right_child = root - 1;
if at < mid {
self.do_point_query(left_child, left, mid, at)
} else {
self.do_point_query(right_child, mid, right, at)
}
}
}
pub fn point_update<T>(&mut self, at: usize, val: T)
where
Node: Pushable<T>,
{
assert!(at < self.n);
self.do_point_update(self.nodes.len() - 1, 0, self.n, at, val);
}
fn do_point_update<T>(&mut self, root: usize, left: usize, right: usize, at: usize, val: T)
where
Node: Pushable<T>,
{
if left + 1 == right {
self.nodes[root].push(val);
} else {
let mid = (left + right) >> 1;
self.push_down(root, mid, right);
let left_child = root - 2 * (right - mid);
let right_child = root - 1;
if at < mid {
self.do_point_update(left_child, left, mid, at, val);
} else {
self.do_point_update(right_child, mid, right, at, val);
}
self.join(root, mid, right);
}
}
pub fn point_through_update<'a, T>(&mut self, at: usize, val: &'a T)
where
Node: Pushable<&'a T>,
{
assert!(at < self.n);
self.do_point_through_update(self.nodes.len() - 1, 0, self.n, at, val);
}
fn do_point_through_update<'a, T>(
&mut self,
root: usize,
left: usize,
right: usize,
at: usize,
val: &'a T,
) where
Node: Pushable<&'a T>,
{
self.nodes[root].push(val);
if left + 1 != right {
let mid = (left + right) >> 1;
self.push_down(root, mid, right);
let left_child = root - 2 * (right - mid);
let right_child = root - 1;
if at < mid {
self.do_point_through_update(left_child, left, mid, at, val);
} else {
self.do_point_through_update(right_child, mid, right, at, val);
}
}
}
pub fn point_operation<Args, Res>(
&mut self,
op: &mut dyn PointOperation<Node, Args, Res>,
args: Args,
) -> Res {
assert_ne!(self.n, 0);
self.do_point_operation(op, self.nodes.len() - 1, 0, self.n, args)
}
fn do_point_operation<Args, Res>(
&mut self,
op: &mut dyn PointOperation<Node, Args, Res>,
root: usize,
left: usize,
right: usize,
args: Args,
) -> Res {
if left + 1 == right {
op.adjust_leaf(&mut self.nodes[root], left, args)
} else {
let mid = (left + right) >> 1;
self.push_down(root, mid, right);
let left_child = root - 2 * (right - mid);
let right_child = root - 1;
let (l, r) = self.nodes.split_at_mut(root);
let (l, m) = l.split_at_mut(right_child);
let direction = op.select_branch(
&mut r[0],
&mut l[left_child],
&mut m[0],
&args,
left,
mid,
right,
);
let res = match direction {
Direction::Left => self.do_point_operation(op, left_child, left, mid, args),
Direction::Right => self.do_point_operation(op, right_child, mid, right, args),
};
self.join(root, mid, right);
res
}
}
pub fn update<'a, T>(&mut self, range: impl RangeBounds<usize>, val: &'a T)
where
Node: Pushable<&'a T>,
{
let (from, to) = clamp(range, self.n);
self.do_update(self.nodes.len() - 1, 0, self.n, from, to, val)
}
pub fn do_update<'a, T>(
&mut self,
root: usize,
left: usize,
right: usize,
from: usize,
to: usize,
val: &'a T,
) where
Node: Pushable<&'a T>,
{
when! {
left >= to || right <= from => {},
left >= from && right <= to => self.nodes[root].push(val),
else => {
let mid = (left + right) >> 1;
self.push_down(root, mid, right);
let left_child = root - 2 * (right - mid);
let right_child = root - 1;
self.do_update(left_child, left, mid, from, to, val);
self.do_update(right_child, mid, right, from, to, val);
self.join(root, mid, right);
},
}
}
pub fn operation<Args, Res>(
&mut self,
range: impl RangeBounds<usize>,
op: &mut dyn Operation<Node, Args, Res>,
args: &Args,
) -> Res {
let (from, to) = clamp(range, self.n);
self.do_operation(self.nodes.len() - 1, 0, self.n, from, to, op, args)
}
pub fn do_operation<Args, Res>(
&mut self,
root: usize,
left: usize,
right: usize,
from: usize,
to: usize,
op: &mut dyn Operation<Node, Args, Res>,
args: &Args,
) -> Res {
when! {
left >= to || right <= from => op.empty_result(left, right, args),
left >= from && right <= to => op.process_result(&mut self.nodes[root], args),
else => {
let mid = (left + right) >> 1;
self.push_down(root, mid, right);
let left_child = root - 2 * (right - mid);
let right_child = root - 1;
let left_result = self.do_operation(left_child, left, mid, from, to, op, args);
let right_result = self.do_operation(right_child, mid, right, from, to, op, args);
self.join(root, mid, right);
op.join_results(left_result, right_result, args)
},
}
}
pub fn binary_search<Res>(
&mut self,
wh: impl FnMut(&Node, &Node) -> Direction,
calc: impl FnMut(&Node, usize) -> Res,
) -> Res {
self.do_binary_search(self.nodes.len() - 1, 0, self.n, wh, calc)
}
fn do_binary_search<Res>(
&mut self,
root: usize,
left: usize,
right: usize,
mut wh: impl FnMut(&Node, &Node) -> Direction,
mut calc: impl FnMut(&Node, usize) -> Res,
) -> Res {
if left + 1 == right {
calc(&self.nodes[root], left)
} else {
let mid = (left + right) >> 1;
self.push_down(root, mid, right);
let left_child = root - 2 * (right - mid);
let right_child = root - 1;
let direction = wh(&self.nodes[left_child], &self.nodes[right_child]);
match direction {
Direction::Left => self.do_binary_search(left_child, left, mid, wh, calc),
Direction::Right => self.do_binary_search(right_child, mid, right, wh, calc),
}
}
}
fn join(&mut self, root: usize, mid: usize, right: usize) {
let left_child = root - 2 * (right - mid);
let right_child = root - 1;
let (left_node, right_node) = self.nodes.split_at_mut(root);
right_node[0].join(&left_node[left_child], &left_node[right_child]);
}
fn do_push_down(&mut self, parent: usize, to: usize) {
let (left_nodes, right_nodes) = self.nodes.split_at_mut(parent);
left_nodes[to].accumulate(&right_nodes[0]);
}
fn push_down(&mut self, root: usize, mid: usize, right: usize) {
self.do_push_down(root, root - 2 * (right - mid));
self.do_push_down(root, root - 1);
self.nodes[root].reset_delta();
}
pub fn query<T>(&mut self, range: impl RangeBounds<usize>) -> T
where
Node: QueryResult<T, ()>,
{
let (from, to) = clamp(range, self.n);
if from >= to {
Node::empty_result(&())
} else {
self.do_query(self.nodes.len() - 1, 0, self.n, from, to, &())
}
}
pub fn query_with_args<T, Args>(&mut self, range: impl RangeBounds<usize>, args: &Args) -> T
where
Node: QueryResult<T, Args>,
{
let (from, to) = clamp(range, self.n);
if from >= to {
Node::empty_result(args)
} else {
self.do_query(self.nodes.len() - 1, 0, self.n, from, to, args)
}
}
fn do_query<T, Args>(
&mut self,
root: usize,
left: usize,
right: usize,
from: usize,
to: usize,
args: &Args,
) -> T
where
Node: QueryResult<T, Args>,
{
if left >= from && right <= to {
self.nodes[root].result(args)
} else {
let mid = (left + right) >> 1;
self.push_down(root, mid, right);
let left_child = root - 2 * (right - mid);
let right_child = root - 1;
when! {
to <= mid => self.do_query(left_child, left, mid, from, to, args),
from >= mid => self.do_query(right_child, mid, right, from, to, args),
else => {
let left_result = self.do_query(left_child, left, mid, from, to, args);
let right_result = self.do_query(right_child, mid, right, from, to, args);
Node::join_results(left_result, right_result, args, left, mid, right)
},
}
}
}
}
pub trait PointOperation<Node: SegmentTreeNode, Args, Res = Node> {
fn adjust_leaf(&mut self, leaf: &mut Node, at: usize, args: Args) -> Res;
fn select_branch(
&mut self,
root: &mut Node,
left_child: &mut Node,
right_child: &mut Node,
args: &Args,
left: usize,
mid: usize,
right: usize,
) -> Direction;
}
pub struct PointOperationClosure<'s, Node: SegmentTreeNode, Args, Res = Node> {
adjust_leaf: Box<dyn FnMut(&mut Node, usize, Args) -> Res + 's>,
select_branch: Box<
dyn FnMut(&mut Node, &mut Node, &mut Node, &Args, usize, usize, usize) -> Direction + 's,
>,
phantom_node: PhantomData<Node>,
phantom_args: PhantomData<Args>,
phantom_res: PhantomData<Res>,
}
impl<'s, Node: SegmentTreeNode, Args, Res> PointOperationClosure<'s, Node, Args, Res> {
pub fn new<F1, F2>(adjust_leaf: F1, select_branch: F2) -> Self
where
F1: FnMut(&mut Node, usize, Args) -> Res + 's,
F2: FnMut(&mut Node, &mut Node, &mut Node, &Args, usize, usize, usize) -> Direction + 's,
{
Self {
adjust_leaf: Box::new(adjust_leaf),
select_branch: Box::new(select_branch),
phantom_node: Default::default(),
phantom_args: Default::default(),
phantom_res: Default::default(),
}
}
}
impl<'s, Node: SegmentTreeNode, Args, Res> PointOperation<Node, Args, Res>
for PointOperationClosure<'s, Node, Args, Res>
{
fn adjust_leaf(&mut self, leaf: &mut Node, at: usize, args: Args) -> Res {
(self.adjust_leaf)(leaf, at, args)
}
fn select_branch(
&mut self,
root: &mut Node,
left_child: &mut Node,
right_child: &mut Node,
args: &Args,
left: usize,
mid: usize,
right: usize,
) -> Direction {
(self.select_branch)(root, left_child, right_child, args, left, mid, right)
}
}
pub trait Operation<Node: SegmentTreeNode, Args, Res = Node> {
fn process_result(&mut self, node: &mut Node, args: &Args) -> Res;
fn join_results(&mut self, left_res: Res, right_res: Res, args: &Args) -> Res;
fn empty_result(&mut self, left: usize, right: usize, args: &Args) -> Res;
}
pub struct OperationClosure<'s, Node: SegmentTreeNode, Args, Res = Node> {
process_result: Box<dyn FnMut(&mut Node, &Args) -> Res + 's>,
join_results: Box<dyn FnMut(Res, Res, &Args) -> Res + 's>,
empty_result: Box<dyn FnMut(usize, usize, &Args) -> Res + 's>,
phantom_node: PhantomData<Node>,
phantom_args: PhantomData<Args>,
phantom_res: PhantomData<Res>,
}
impl<'s, Node: SegmentTreeNode, Args, Res> OperationClosure<'s, Node, Args, Res> {
pub fn new<F1, F2, F3>(process_result: F1, join_results: F2, empty_result: F3) -> Self
where
F1: FnMut(&mut Node, &Args) -> Res + 's,
F2: FnMut(Res, Res, &Args) -> Res + 's,
F3: FnMut(usize, usize, &Args) -> Res + 's,
{
Self {
process_result: Box::new(process_result),
join_results: Box::new(join_results),
empty_result: Box::new(empty_result),
phantom_node: Default::default(),
phantom_args: Default::default(),
phantom_res: Default::default(),
}
}
}
impl<'s, Node: SegmentTreeNode, Args, Res> Operation<Node, Args, Res>
for OperationClosure<'s, Node, Args, Res>
{
fn process_result(&mut self, node: &mut Node, args: &Args) -> Res {
(self.process_result)(node, args)
}
fn join_results(&mut self, left_res: Res, right_res: Res, args: &Args) -> Res {
(self.join_results)(left_res, right_res, args)
}
fn empty_result(&mut self, left: usize, right: usize, args: &Args) -> Res {
(self.empty_result)(left, right, args)
}
}
}
pub mod vec_ext {
pub mod default {
pub fn default_vec<T: Default>(len: usize) -> Vec<T> {
let mut v = Vec::with_capacity(len);
for _ in 0..len {
v.push(T::default());
}
v
}
}
pub mod sorted {
pub trait Sorted {
fn sorted(self) -> Self;
}
impl<T: Ord> Sorted for Vec<T> {
fn sorted(mut self) -> Self {
self.sort();
self
}
}
}
}
}
pub mod io {
pub mod input {
use crate::algo_lib::collections::vec_ext::default::default_vec;
use std::io::Read;
pub struct Input<'s> {
input: &'s mut (dyn Read + Send),
buf: Vec<u8>,
at: usize,
buf_read: usize,
}
macro_rules! read_impl {
($t: ty, $read_name: ident, $read_vec_name: ident) => {
pub fn $read_name(&mut self) -> $t {
self.read()
}
pub fn $read_vec_name(&mut self, len: usize) -> Vec<$t> {
self.read_vec(len)
}
};
($t: ty, $read_name: ident, $read_vec_name: ident, $read_pair_vec_name: ident) => {
read_impl!($t, $read_name, $read_vec_name);
pub fn $read_pair_vec_name(&mut self, len: usize) -> Vec<($t, $t)> {
self.read_vec(len)
}
};
}
impl<'s> Input<'s> {
const DEFAULT_BUF_SIZE: usize = 4096;
pub fn new(input: &'s mut (dyn Read + Send)) -> Self {
Self {
input,
buf: default_vec(Self::DEFAULT_BUF_SIZE),
at: 0,
buf_read: 0,
}
}
pub fn new_with_size(input: &'s mut (dyn Read + Send), buf_size: usize) -> Self {
Self {
input,
buf: default_vec(buf_size),
at: 0,
buf_read: 0,
}
}
pub fn get(&mut self) -> Option<u8> {
if self.refill_buffer() {
let res = self.buf[self.at];
self.at += 1;
if res == b'\r' {
if self.refill_buffer() && self.buf[self.at] == b'\n' {
self.at += 1;
}
return Some(b'\n');
}
Some(res)
} else {
None
}
}
pub fn peek(&mut self) -> Option<u8> {
if self.refill_buffer() {
let res = self.buf[self.at];
Some(if res == b'\r' { b'\n' } else { res })
} else {
None
}
}
pub fn skip_whitespace(&mut self) {
while let Some(b) = self.peek() {
if !b.is_ascii_whitespace() {
return;
}
self.get();
}
}
pub fn next_token(&mut self) -> Option<Vec<u8>> {
self.skip_whitespace();
let mut res = Vec::new();
while let Some(c) = self.get() {
if c.is_ascii_whitespace() {
break;
}
res.push(c);
}
if res.is_empty() {
None
} else {
Some(res)
}
}
//noinspection RsSelfConvention
pub fn is_exhausted(&mut self) -> bool {
self.peek().is_none()
}
//noinspection RsSelfConvention
pub fn is_empty(&mut self) -> bool {
self.skip_whitespace();
self.is_exhausted()
}
pub fn read<T: Readable>(&mut self) -> T {
T::read(self)
}
pub fn read_vec<T: Readable>(&mut self, size: usize) -> Vec<T> {
let mut res = Vec::with_capacity(size);
for _ in 0..size {
res.push(self.read());
}
res
}
pub fn read_char(&mut self) -> u8 {
self.skip_whitespace();
self.get().unwrap()
}
read_impl!(u32, read_unsigned, read_unsigned_vec);
read_impl!(u64, read_u64, read_u64_vec);
read_impl!(usize, read_size, read_size_vec, read_size_pair_vec);
read_impl!(i32, read_int, read_int_vec, read_int_pair_vec);
read_impl!(i64, read_long, read_long_vec, read_long_pair_vec);
read_impl!(i128, read_i128, read_i128_vec);
fn refill_buffer(&mut self) -> bool {
if self.at == self.buf_read {
self.at = 0;
self.buf_read = self.input.read(&mut self.buf).unwrap();
self.buf_read != 0
} else {
true
}
}
}
pub trait Readable {
fn read(input: &mut Input) -> Self;
}
impl Readable for u8 {
fn read(input: &mut Input) -> Self {
input.read_char()
}
}
impl<T: Readable> Readable for Vec<T> {
fn read(input: &mut Input) -> Self {
let size = input.read();
input.read_vec(size)
}
}
macro_rules! read_integer {
($($t:ident)+) => {$(
impl Readable for $t {
fn read(input: &mut Input) -> Self {
input.skip_whitespace();
let mut c = input.get().unwrap();
let sgn = match c {
b'-' => {
c = input.get().unwrap();
true
}
b'+' => {
c = input.get().unwrap();
false
}
_ => false,
};
let mut res = 0;
loop {
assert!(c.is_ascii_digit());
res *= 10;
let d = (c - b'0') as $t;
if sgn {
res -= d;
} else {
res += d;
}
match input.get() {
None => break,
Some(ch) => {
if ch.is_ascii_whitespace() {
break;
} else {
c = ch;
}
}
}
}
res
}
}
)+};
}
read_integer!(i8 i16 i32 i64 i128 isize u16 u32 u64 u128 usize);
macro_rules! tuple_readable {
($($name:ident)+) => {
impl<$($name: Readable), +> Readable for ($($name,)+) {
fn read(input: &mut Input) -> Self {
($($name::read(input),)+)
}
}
}
}
tuple_readable! {T}
tuple_readable! {T U}
tuple_readable! {T U V}
tuple_readable! {T U V X}
tuple_readable! {T U V X Y}
tuple_readable! {T U V X Y Z}
tuple_readable! {T U V X Y Z A}
tuple_readable! {T U V X Y Z A B}
tuple_readable! {T U V X Y Z A B C}
tuple_readable! {T U V X Y Z A B C D}
tuple_readable! {T U V X Y Z A B C D E}
tuple_readable! {T U V X Y Z A B C D E F}
impl Read for Input<'_> {
fn read(&mut self, buf: &mut [u8]) -> std::io::Result<usize> {
if self.at == self.buf_read {
self.input.read(buf)
} else {
let mut i = 0;
while i < buf.len() && self.at < self.buf_read {
buf[i] = self.buf[self.at];
i += 1;
self.at += 1;
}
Ok(i)
}
}
}
}
pub mod output {
use crate::algo_lib::collections::vec_ext::default::default_vec;
use std::cmp::Reverse;
use std::io::stderr;
use std::io::Stderr;
use std::io::Write;
#[derive(Copy, Clone)]
pub enum BoolOutput {
YesNo,
YesNoCaps,
PossibleImpossible,
Custom(&'static str, &'static str),
}
impl BoolOutput {
pub fn output(&self, output: &mut Output, val: bool) {
(if val { self.yes() } else { self.no() }).write(output);
}
fn yes(&self) -> &str {
match self {
BoolOutput::YesNo => "Yes",
BoolOutput::YesNoCaps => "YES",
BoolOutput::PossibleImpossible => "Possible",
BoolOutput::Custom(yes, _) => yes,
}
}
fn no(&self) -> &str {
match self {
BoolOutput::YesNo => "No",
BoolOutput::YesNoCaps => "NO",
BoolOutput::PossibleImpossible => "Impossible",
BoolOutput::Custom(_, no) => no,
}
}
}
pub struct Output<'s> {
output: &'s mut dyn Write,
buf: Vec<u8>,
at: usize,
auto_flush: bool,
bool_output: BoolOutput,
}
impl<'s> Output<'s> {
const DEFAULT_BUF_SIZE: usize = 4096;
pub fn new(output: &'s mut dyn Write) -> Self {
Self {
output,
buf: default_vec(Self::DEFAULT_BUF_SIZE),
at: 0,
auto_flush: false,
bool_output: BoolOutput::YesNoCaps,
}
}
pub fn new_with_auto_flush(output: &'s mut dyn Write) -> Self {
Self {
output,
buf: default_vec(Self::DEFAULT_BUF_SIZE),
at: 0,
auto_flush: true,
bool_output: BoolOutput::YesNoCaps,
}
}
pub fn flush(&mut self) {
if self.at != 0 {
self.output.write_all(&self.buf[..self.at]).unwrap();
self.output.flush().unwrap();
self.at = 0;
}
}
pub fn print<T: Writable>(&mut self, s: T) {
s.write(self);
self.maybe_flush();
}
pub fn print_line<T: Writable>(&mut self, s: T) {
self.print(s);
self.put(b'\n');
self.maybe_flush();
}
pub fn put(&mut self, b: u8) {
self.buf[self.at] = b;
self.at += 1;
if self.at == self.buf.len() {
self.flush();
}
}
pub fn maybe_flush(&mut self) {
if self.auto_flush {
self.flush();
}
}
pub fn print_per_line<T: Writable>(&mut self, arg: &[T]) {
self.print_per_line_iter(arg.iter());
}
pub fn print_iter<T: Writable, I: Iterator<Item = T>>(&mut self, iter: I) {
let mut first = true;
for e in iter {
if first {
first = false;
} else {
self.put(b' ');
}
e.write(self);
}
}
pub fn print_line_iter<T: Writable, I: Iterator<Item = T>>(&mut self, iter: I) {
self.print_iter(iter);
self.put(b'\n');
}
pub fn print_per_line_iter<T: Writable, I: Iterator<Item = T>>(&mut self, iter: I) {
for e in iter {
e.write(self);
self.put(b'\n');
}
}
pub fn set_bool_output(&mut self, bool_output: BoolOutput) {
self.bool_output = bool_output;
}
}
impl Write for Output<'_> {
fn write(&mut self, buf: &[u8]) -> std::io::Result<usize> {
let mut start = 0usize;
let mut rem = buf.len();
while rem > 0 {
let len = (self.buf.len() - self.at).min(rem);
self.buf[self.at..self.at + len].copy_from_slice(&buf[start..start + len]);
self.at += len;
if self.at == self.buf.len() {
self.flush();
}
start += len;
rem -= len;
}
self.maybe_flush();
Ok(buf.len())
}
fn flush(&mut self) -> std::io::Result<()> {
self.flush();
Ok(())
}
}
pub trait Writable {
fn write(&self, output: &mut Output);
}
impl Writable for &str {
fn write(&self, output: &mut Output) {
output.write_all(self.as_bytes()).unwrap();
}
}
impl Writable for String {
fn write(&self, output: &mut Output) {
output.write_all(self.as_bytes()).unwrap();
}
}
impl Writable for char {
fn write(&self, output: &mut Output) {
output.put(*self as u8);
}
}
impl Writable for u8 {
fn write(&self, output: &mut Output) {
output.put(*self);
}
}
impl<T: Writable> Writable for [T] {
fn write(&self, output: &mut Output) {
output.print_iter(self.iter());
}
}
impl<T: Writable, const N: usize> Writable for [T; N] {
fn write(&self, output: &mut Output) {
output.print_iter(self.iter());
}
}
impl<T: Writable + ?Sized> Writable for &T {
fn write(&self, output: &mut Output) {
T::write(self, output)
}
}
impl<T: Writable> Writable for Vec<T> {
fn write(&self, output: &mut Output) {
self.as_slice().write(output);
}
}
impl Writable for () {
fn write(&self, _output: &mut Output) {}
}
macro_rules! write_to_string {
($($t:ident)+) => {$(
impl Writable for $t {
fn write(&self, output: &mut Output) {
self.to_string().write(output);
}
}
)+};
}
write_to_string!(u16 u32 u64 u128 usize i8 i16 i32 i64 i128 isize);
macro_rules! tuple_writable {
($name0:ident $($name:ident: $id:tt )*) => {
impl<$name0: Writable, $($name: Writable,)*> Writable for ($name0, $($name,)*) {
fn write(&self, out: &mut Output) {
self.0.write(out);
$(
out.put(b' ');
self.$id.write(out);
)*
}
}
}
}
tuple_writable! {T}
tuple_writable! {T U:1}
tuple_writable! {T U:1 V:2}
tuple_writable! {T U:1 V:2 X:3}
tuple_writable! {T U:1 V:2 X:3 Y:4}
tuple_writable! {T U:1 V:2 X:3 Y:4 Z:5}
tuple_writable! {T U:1 V:2 X:3 Y:4 Z:5 A:6}
tuple_writable! {T U:1 V:2 X:3 Y:4 Z:5 A:6 B:7}
tuple_writable! {T U:1 V:2 X:3 Y:4 Z:5 A:6 B:7 C:8}
impl<T: Writable> Writable for Option<T> {
fn write(&self, output: &mut Output) {
match self {
None => (-1).write(output),
Some(t) => t.write(output),
}
}
}
impl Writable for bool {
fn write(&self, output: &mut Output) {
let bool_output = output.bool_output;
bool_output.output(output, *self)
}
}
impl<T: Writable> Writable for Reverse<T> {
fn write(&self, output: &mut Output) {
self.0.write(output);
}
}
static mut ERR: Option<Stderr> = None;
pub fn err() -> Output<'static> {
unsafe {
if ERR.is_none() {
ERR = Some(stderr());
}
Output::new_with_auto_flush(ERR.as_mut().unwrap())
}
}
}
}
pub mod misc {
pub mod direction {
#[derive(Copy, Clone)]
pub enum Direction {
Left,
Right,
}
}
pub mod test_type {
pub enum TestType {
Single,
MultiNumber,
MultiEof,
}
pub enum TaskType {
Classic,
Interactive,
}
}
pub mod when {
#[macro_export]
macro_rules! when {
{$($cond: expr => $then: expr,)*} => {
match () {
$(_ if $cond => $then,)*
_ => unreachable!(),
}
};
{$($cond: expr => $then: expr,)* else $(=>)? $else: expr$(,)?} => {
match () {
$(_ if $cond => $then,)*
_ => $else,
}
};
}
}
}
pub mod numbers {
pub mod num_traits {
pub mod algebra {
use crate::algo_lib::numbers::num_traits::invertible::Invertible;
use std::ops::Add;
use std::ops::AddAssign;
use std::ops::Div;
use std::ops::DivAssign;
use std::ops::Mul;
use std::ops::MulAssign;
use std::ops::Neg;
use std::ops::Rem;
use std::ops::RemAssign;
use std::ops::Sub;
use std::ops::SubAssign;
pub trait Zero {
fn zero() -> Self;
}
pub trait One {
fn one() -> Self;
}
pub trait AdditionMonoid: Add<Output = Self> + AddAssign + Zero + Eq + Sized {}
impl<T: Add<Output = Self> + AddAssign + Zero + Eq> AdditionMonoid for T {}
pub trait AdditionMonoidWithSub: AdditionMonoid + Sub<Output = Self> + SubAssign {}
impl<T: AdditionMonoid + Sub<Output = Self> + SubAssign> AdditionMonoidWithSub for T {}
pub trait AdditionGroup: AdditionMonoidWithSub + Neg<Output = Self> {}
impl<T: AdditionMonoidWithSub + Neg<Output = Self>> AdditionGroup for T {}
pub trait MultiplicationMonoid: Mul<Output = Self> + MulAssign + One + Eq + Sized {}
impl<T: Mul<Output = Self> + MulAssign + One + Eq> MultiplicationMonoid for T {}
pub trait IntegerMultiplicationMonoid:
MultiplicationMonoid + Div<Output = Self> + Rem<Output = Self> + DivAssign + RemAssign
{
}
impl<T: MultiplicationMonoid + Div<Output = Self> + Rem<Output = Self> + DivAssign + RemAssign>
IntegerMultiplicationMonoid for T
{
}
pub trait MultiplicationGroup:
MultiplicationMonoid + Div<Output = Self> + DivAssign + Invertible<Output = Self>
{
}
impl<T: MultiplicationMonoid + Div<Output = Self> + DivAssign + Invertible<Output = Self>>
MultiplicationGroup for T
{
}
pub trait SemiRing: AdditionMonoid + MultiplicationMonoid {}
impl<T: AdditionMonoid + MultiplicationMonoid> SemiRing for T {}
pub trait SemiRingWithSub: AdditionMonoidWithSub + SemiRing {}
impl<T: AdditionMonoidWithSub + SemiRing> SemiRingWithSub for T {}
pub trait Ring: SemiRing + AdditionGroup {}
impl<T: SemiRing + AdditionGroup> Ring for T {}
pub trait IntegerSemiRing: SemiRing + IntegerMultiplicationMonoid {}
impl<T: SemiRing + IntegerMultiplicationMonoid> IntegerSemiRing for T {}
pub trait IntegerSemiRingWithSub: SemiRingWithSub + IntegerSemiRing {}
impl<T: SemiRingWithSub + IntegerSemiRing> IntegerSemiRingWithSub for T {}
pub trait IntegerRing: IntegerSemiRing + Ring {}
impl<T: IntegerSemiRing + Ring> IntegerRing for T {}
pub trait Field: Ring + MultiplicationGroup {}
impl<T: Ring + MultiplicationGroup> Field for T {}
macro_rules! zero_one_integer_impl {
($($t: ident)+) => {$(
impl Zero for $t {
fn zero() -> Self {
0
}
}
impl One for $t {
fn one() -> Self {
1
}
}
)+};
}
zero_one_integer_impl!(i128 i64 i32 i16 i8 isize u128 u64 u32 u16 u8 usize);
}
pub mod invertible {
pub trait Invertible {
type Output;
fn inv(&self) -> Option<Self::Output>;
}
}
}
}
}
fn main() {
let mut sin = std::io::stdin();
let input = algo_lib::io::input::Input::new(&mut sin);
let mut stdout = std::io::stdout();
let output = algo_lib::io::output::Output::new(&mut stdout);
solution::run(input, output);
}
这程序好像有点Bug,我给组数据试试?
Details
Tip: Click on the bar to expand more detailed information
Test #1:
score: 100
Accepted
time: 0ms
memory: 2208kb
input:
5 17 2 3 4 6 1 5 8 2 4 4 3 3 7 5 5
output:
109
result:
ok single line: '109'
Test #2:
score: 0
Accepted
time: 0ms
memory: 2076kb
input:
12 62 503792 9 10 607358 1 3 600501 10 10 33249 4 4 774438 6 6 197692 3 6 495807 8 8 790225 5 9 77272 3 8 494819 4 9 894779 3 9 306279 5 6
output:
35204500
result:
ok single line: '35204500'
Test #3:
score: 0
Accepted
time: 0ms
memory: 2160kb
input:
15 32 835418 2 3 178262 1 3 527643 2 2 519710 1 1 774544 3 3 82312 1 1 808199 1 1 809396 1 3 255882 1 3 80467 1 3 874973 1 3 813965 1 2 198275 1 2 152356 1 3 802055 1 1
output:
22000255
result:
ok single line: '22000255'
Test #4:
score: 0
Accepted
time: 0ms
memory: 2108kb
input:
13 20 526447 1 1 807398 2 2 4167 1 2 944031 2 2 830685 2 2 394251 1 2 505011 1 2 968848 1 1 58170 1 3 32504 1 1 792273 3 3 196120 1 2 714507 1 1
output:
12878768
result:
ok single line: '12878768'
Test #5:
score: 0
Accepted
time: 0ms
memory: 2112kb
input:
13 32 582584 1 3 335440 3 3 971984 1 2 864169 1 2 528515 1 1 382399 1 2 459855 1 2 406909 2 3 66780 2 3 885118 3 3 434844 1 2 93331 1 3 502509 1 3
output:
22065034
result:
ok single line: '22065034'
Test #6:
score: 0
Accepted
time: 0ms
memory: 2148kb
input:
12 77 30244 1 7 518214 3 8 486001 8 9 152634 2 3 180255 3 4 791887 1 6 635820 2 9 881171 3 5 337905 3 8 683182 5 5 300786 3 6 339094 7 9
output:
50453764
result:
ok single line: '50453764'
Test #7:
score: 0
Accepted
time: 0ms
memory: 2132kb
input:
10 3923726 826284 215861 638800 471693 146746 886003 140800 532315 684546 673434 604071 814259 170671 299465 525449 104262 689547 855391 215333 591975 803421 795321 31606 984783 103838 361911 601318 145693 450227 686945
output:
1597735409747
result:
ok single line: '1597735409747'
Test #8:
score: 0
Accepted
time: 45ms
memory: 10636kb
input:
100000 16648414311 252800 55607 195981 157144 548469 789695 643048 2 2 907957 3 3 32532 231618 316365 194428 227513 762023 4231 393553 699179 898052 3 5 507551 3 5 747498 1 4 857939 9 9 440056 764429 796585 495571 117772 838593 4059 551203 870687 60877 597981 770178 593237 4 10 438147 218335 370780 ...
output:
4148641232436282
result:
ok single line: '4148641232436282'
Test #9:
score: 0
Accepted
time: 42ms
memory: 10592kb
input:
100000 14997174848 996832 2 5 193379 411081 976749 339827 553492 639067 127364 131886 237768 615192 3 9 417612 599185 637969 812326 2 5 22605 80976 90557 350917 119223 755129 807528 7 8 165108 327186 793786 126946 530792 700713 246467 387234 557026 286888 485816 869662 398882 73798 458939 651741 3 9...
output:
3763949202789374
result:
ok single line: '3763949202789374'
Test #10:
score: 0
Accepted
time: 44ms
memory: 10664kb
input:
99999 49959949282 541788 999954 999965 269794 8 9 446939 999985 999990 994146 7 13 976318 999916 999995 372141 999918 999934 398999 999949 999983 736560 4 7 753380 999933 999979 664693 12 14 336068 999904 999914 337406 11 11 153015 2 3 989608 1 15 61489 999921 999977 438155 999928 999955 374725 6 14...
output:
24950941271114177
result:
ok single line: '24950941271114177'
Test #11:
score: 0
Accepted
time: 40ms
memory: 10648kb
input:
100000 50094841499 989502 999933 999995 613471 999942 999989 987086 999912 999912 170196 8 8 992426 7 8 935974 999985 999993 509210 7 8 136227 999901 999966 975351 3 8 979031 4 6 160909 999918 999956 919448 6 6 166331 3 10 412011 1 2 815782 999967 999985 272771 1 9 414870 6 10 991275 6 8 568088 9999...
output:
25091133401633321
result:
ok single line: '25091133401633321'
Test #12:
score: 0
Accepted
time: 0ms
memory: 2156kb
input:
1 1 1000000 1 1
output:
1000000
result:
ok single line: '1000000'
Test #13:
score: 0
Accepted
time: 30ms
memory: 10772kb
input:
99999 99999 2 1 1 2 1 1 4 1 1 9 1 1 1 1 1 2 1 1 4 1 1 8 1 1 7 1 1 5 1 1 6 1 1 8 1 1 10 1 1 5 1 1 7 1 1 3 1 1 4 1 1 7 1 1 8 1 1 7 1 1 7 1 1 6 1 1 8 1 1 1 1 1 5 1 1 1 1 1 8 1 1 5 1 1 9 1 1 3 1 1 10 1 1 8 1 1 4 1 1 3 1 1 9 1 1 2 1 1 1 1 1 10 1 1 5 1 1 3 1 1 3 1 1 5 1 1 4 1 1 7 1 1 6 1 1 3 1 1 7 1 1 2 1...
output:
549692
result:
ok single line: '549692'
Test #14:
score: 0
Accepted
time: 38ms
memory: 10660kb
input:
100000 100000000000 9 1000000 1000000 9 1000000 1000000 3 1000000 1000000 8 1000000 1000000 7 1000000 1000000 7 1000000 1000000 8 1000000 1000000 10 1000000 1000000 9 1000000 1000000 3 1000000 1000000 5 1000000 1000000 3 1000000 1000000 6 1000000 1000000 5 1000000 1000000 8 1000000 1000000 8 1000000...
output:
549817000000
result:
ok single line: '549817000000'
Test #15:
score: 0
Accepted
time: 38ms
memory: 10736kb
input:
100000 671789 5 2 10 9 5 7 8 2 9 5 8 10 8 2 9 1 1 4 2 4 4 2 4 10 1 7 8 6 2 5 6 2 9 8 2 8 7 4 9 7 2 7 6 9 10 2 8 10 5 2 5 10 7 7 8 10 10 1 2 10 9 5 8 1 2 10 7 7 10 2 1 8 8 3 5 9 2 6 9 6 7 1 2 6 1 5 9 4 3 9 9 3 9 6 4 5 10 7 10 9 2 6 4 1 1 5 7 10 9 3 8 10 3 7 2 3 7 5 3 8 9 6 10 10 3 7 8 3 10 8 7 8 9 2 ...
output:
4980663
result:
ok single line: '4980663'
Test #16:
score: 0
Accepted
time: 37ms
memory: 10752kb
input:
100000 43584087032 3 308557 419587 10 44993 179507 3 558835 576023 4 479689 820340 7 4935 112717 5 322154 540751 9 153422 454200 3 487079 842717 9 21773 328114 9 690130 713456 4 518679 947666 7 301275 983364 3 911034 987000 2 15489 33232 5 324080 855780 10 274011 978357 7 436627 535933 6 255072 3389...
output:
285837954666
result:
ok single line: '285837954666'
Test #17:
score: 0
Accepted
time: 39ms
memory: 10724kb
input:
100000 494057 192370 2 5 927249 6 10 481645 1 7 890938 2 9 931657 2 8 117542 1 10 701551 1 5 476263 2 8 962638 9 9 141062 2 7 492687 2 5 162204 5 10 287629 1 3 73695 4 6 532420 4 5 148287 4 9 336392 1 10 26418 2 3 604407 6 7 363085 6 10 588785 4 10 935894 3 7 635464 8 9 4054 7 10 788212 5 8 784626 4...
output:
301267755741
result:
ok single line: '301267755741'
Test #18:
score: 0
Accepted
time: 41ms
memory: 10652kb
input:
99999 45855284516 265992 22744 429276 61438 55667 94035 744311 127123 820013 525673 503191 963233 405981 163221 622202 441929 48325 769270 292426 331849 684679 837775 169205 310287 781428 180746 471729 904737 496244 605722 6438 573095 848106 660782 666291 899499 588344 230725 908374 187969 27281 234...
output:
29154320003042268
result:
ok single line: '29154320003042268'
Test #19:
score: 0
Accepted
time: 44ms
memory: 10808kb
input:
100000 39658278416 910036 17012 115825 887707 68696 139006 751733 147105 196317 500363 634963 798238 605013 61172 939770 10545 121743 746170 139387 291373 880992 525268 454997 566484 93296 375808 636120 656743 206221 799161 726434 554530 984728 424654 103201 675866 415178 29860 997339 941218 406409 ...
output:
23031701433310233
result:
ok single line: '23031701433310233'
Test #20:
score: 0
Accepted
time: 37ms
memory: 10816kb
input:
100000 384892 829184 1 7 254316 8 10 293723 10 10 200173 3 10 832598 6 10 516217 2 3 576064 5 9 626015 5 7 797096 1 3 297561 7 9 580487 1 10 971989 1 6 48861 2 9 672368 3 7 860889 2 4 236484 1 10 703037 3 10 564708 4 7 735042 6 8 694950 4 4 30648 7 9 943649 4 7 100913 3 10 212727 2 10 706335 4 7 520...
output:
192678722976
result:
ok single line: '192678722976'
Test #21:
score: 0
Accepted
time: 45ms
memory: 10664kb
input:
100000 33276622596 614684 401795 484562 138134 379845 472752 103466 162056 593369 972197 201827 250891 732656 317090 812259 818778 15099 332517 786688 357678 409652 761432 50454 843067 866412 738050 831778 167046 125944 675862 592604 525479 592023 693376 299606 991256 135136 9359 848986 610066 64138...
output:
16632077269836196
result:
ok single line: '16632077269836196'
Test #22:
score: 0
Accepted
time: 38ms
memory: 10604kb
input:
100000 33276622596 6 401795 484562 6 379845 472752 999992 162056 593369 999993 201827 250891 2 317090 812259 2 15099 332517 6 357678 409652 6 50454 843067 4 738050 831778 10 125944 675862 4 525479 592023 999999 299606 991256 999993 9359 848986 999994 641380 733867 3 249084 734251 3 30083 395670 9999...
output:
16633573366541551
result:
ok single line: '16633573366541551'
Test #23:
score: 0
Accepted
time: 42ms
memory: 10728kb
input:
100000 714200 829184 1 7 254316 8 10 293723 10 10 200173 3 10 832598 6 10 516217 2 3 576064 5 9 626015 5 7 797096 1 3 297561 7 9 580487 1 10 971989 1 6 48861 2 9 672368 3 7 860889 2 4 236484 1 10 703037 3 10 564708 4 7 735042 6 8 694950 4 4 30648 7 9 943649 4 7 100913 3 10 212727 2 10 706335 4 7 520...
output:
521973117716
result:
ok single line: '521973117716'
Test #24:
score: 0
Accepted
time: 44ms
memory: 10812kb
input:
100000 66619682922 614684 401795 484562 138134 379845 472752 103466 162056 593369 972197 201827 250891 732656 317090 812259 818778 15099 332517 786688 357678 409652 761432 50454 843067 866412 738050 831778 167046 125944 675862 592604 525479 592023 693376 299606 991256 135136 9359 848986 610066 64138...
output:
49973831031956598
result:
ok single line: '49973831031956598'
Extra Test:
score: 0
Extra Test Passed