QOJ.ac

QOJ

IDProblemSubmitterResultTimeMemoryLanguageFile sizeSubmit timeJudge time
#304014#8005. Crossing the Borderucup-team635#AC ✓1803ms219120kbRust21.3kb2024-01-13 11:27:392024-01-13 11:27:39

Judging History

你现在查看的是最新测评结果

  • [2024-01-13 11:27:39]
  • 评测
  • 测评结果:AC
  • 用时:1803ms
  • 内存:219120kb
  • [2024-01-13 11:27:39]
  • 提交

answer

use std::collections::*;
use std::io::Write;

type Map<K, V> = BTreeMap<K, V>;
type Set<T> = BTreeSet<T>;
type Deque<T> = VecDeque<T>;

type M = ModInt<998244353>;

fn main() {
    input! {
        n: usize,
        w: u32,
        p: [(u32, u32); n],
    }
    let mut p = p;
    p.sort_by_key(|p| p.1);
    let mut sum = vec![0; 1 << n];
    for (i, &(a, _)) in p.iter().enumerate() {
        let sum = &mut sum[..(2 << i)];
        let (l, r) = sum.split_at_mut(1 << i);
        for (r, l) in r.iter_mut().zip(l.iter()) {
            *r = *l + a;
        }
    }
    let inf = p.iter().map(|p| p.1).sum::<u32>() + 1;
    let mut dp = vec![(inf, M::zero()); 1 << (n - 1)];
    for (dp, sum) in dp.iter_mut().zip(sum[(1 << (n - 1))..].iter()) {
        if *sum <= w {
            *dp = (p[n - 1].1, M::one());
        }
    }
    for (i, &(a, b)) in p.iter().enumerate().rev().skip(1) {
        let (src, dst) = dp.split_at_mut(1 << i);
        let w = sum[(1 << i)..(2 << i)]
            .iter()
            .map(|s| if *s <= w { M::one() } else { M::zero() })
            .collect::<Vec<_>>();
        let mut prev = 0;
        while let Some(&(min, _)) = src.iter().filter(|p| p.0 > prev).min_by_key(|p| p.0) {
            let x = src
                .iter()
                .map(|p| if p.0 == min { p.1 } else { M::zero() })
                .collect::<Vec<_>>();
            let y = subset_convolution(&x, &w);
            for (dst, y) in dst.iter_mut().zip(y.iter()) {
                if y.is_zero() {
                    continue;
                }
                if dst.0 > min + b {
                    *dst = (min + b, *y);
                } else if dst.0 == min + b {
                    dst.1 += *y;
                }
            }
            prev = min;
        }
        dp.drain(..(1 << i));
    }
    println!("{} {}", dp[0].0, dp[0].1);
}

// ---------- begin input macro ----------
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
#[macro_export]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

#[macro_export]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[macro_export]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, bytes) => {
        read_value!($iter, String).bytes().collect::<Vec<u8>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
// ---------- end input macro ----------

use std::ops::*;

// ---------- begin trait ----------
pub trait Zero: Sized + Add<Self, Output = Self> {
    fn zero() -> Self;
    fn is_zero(&self) -> bool;
}

pub trait One: Sized + Mul<Self, Output = Self> {
    fn one() -> Self;
    fn is_one(&self) -> bool;
}

pub trait Ring: Zero + One + Sub<Output = Self> {}

pub trait Field: Ring + Div<Output = Self> {}
// ---------- end trait ----------
// ---------- begin modint ----------
pub const fn pow_mod(mut r: u32, mut n: u32, m: u32) -> u32 {
    let mut t = 1;
    while n > 0 {
        if n & 1 == 1 {
            t = (t as u64 * r as u64 % m as u64) as u32;
        }
        r = (r as u64 * r as u64 % m as u64) as u32;
        n >>= 1;
    }
    t
}

pub const fn primitive_root(p: u32) -> u32 {
    let mut m = p - 1;
    let mut f = [1; 30];
    let mut k = 0;
    let mut d = 2;
    while d * d <= m {
        if m % d == 0 {
            f[k] = d;
            k += 1;
        }
        while m % d == 0 {
            m /= d;
        }
        d += 1;
    }
    if m > 1 {
        f[k] = m;
        k += 1;
    }
    let mut g = 1;
    while g < p {
        let mut ok = true;
        let mut i = 0;
        while i < k {
            ok &= pow_mod(g, (p - 1) / f[i], p) > 1;
            i += 1;
        }
        if ok {
            break;
        }
        g += 1;
    }
    g
}

pub const fn is_prime(n: u32) -> bool {
    if n <= 1 {
        return false;
    }
    let mut d = 2;
    while d * d <= n {
        if n % d == 0 {
            return false;
        }
        d += 1;
    }
    true
}

#[derive(Clone, Copy, PartialEq, Eq)]
pub struct ModInt<const M: u32>(u32);

impl<const M: u32> ModInt<{ M }> {
    const REM: u32 = {
        let mut t = 1u32;
        let mut s = !M + 1;
        let mut n = !0u32 >> 2;
        while n > 0 {
            if n & 1 == 1 {
                t = t.wrapping_mul(s);
            }
            s = s.wrapping_mul(s);
            n >>= 1;
        }
        t
    };
    const INI: u64 = ((1u128 << 64) % M as u128) as u64;
    const IS_PRIME: () = assert!(is_prime(M));
    const PRIMITIVE_ROOT: u32 = primitive_root(M);
    const ORDER: usize = 1 << (M - 1).trailing_zeros();
    const fn reduce(x: u64) -> u32 {
        let _ = Self::IS_PRIME;
        let b = (x as u32 * Self::REM) as u64;
        let t = x + b * M as u64;
        let mut c = (t >> 32) as u32;
        if c >= M {
            c -= M;
        }
        c as u32
    }
    const fn multiply(a: u32, b: u32) -> u32 {
        Self::reduce(a as u64 * b as u64)
    }
    pub const fn new(v: u32) -> Self {
        assert!(v < M);
        Self(Self::reduce(v as u64 * Self::INI))
    }
    pub const fn const_mul(&self, rhs: Self) -> Self {
        Self(Self::multiply(self.0, rhs.0))
    }
    pub const fn pow(&self, mut n: u64) -> Self {
        let mut t = Self::new(1);
        let mut r = *self;
        while n > 0 {
            if n & 1 == 1 {
                t = t.const_mul(r);
            }
            r = r.const_mul(r);
            n >>= 1;
        }
        t
    }
    pub const fn inv(&self) -> Self {
        assert!(self.0 != 0);
        self.pow(M as u64 - 2)
    }
    pub const fn get(&self) -> u32 {
        Self::reduce(self.0 as u64)
    }
    pub const fn zero() -> Self {
        Self::new(0)
    }
    pub const fn one() -> Self {
        Self::new(1)
    }
}

impl<const M: u32> Add for ModInt<{ M }> {
    type Output = Self;
    fn add(self, rhs: Self) -> Self::Output {
        let mut v = self.0 + rhs.0;
        if v >= M {
            v -= M;
        }
        Self(v)
    }
}

impl<const M: u32> Sub for ModInt<{ M }> {
    type Output = Self;
    fn sub(self, rhs: Self) -> Self::Output {
        let mut v = self.0 - rhs.0;
        if self.0 < rhs.0 {
            v += M;
        }
        Self(v)
    }
}

impl<const M: u32> Mul for ModInt<{ M }> {
    type Output = Self;
    fn mul(self, rhs: Self) -> Self::Output {
        self.const_mul(rhs)
    }
}

impl<const M: u32> Div for ModInt<{ M }> {
    type Output = Self;
    fn div(self, rhs: Self) -> Self::Output {
        self * rhs.inv()
    }
}

impl<const M: u32> AddAssign for ModInt<{ M }> {
    fn add_assign(&mut self, rhs: Self) {
        *self = *self + rhs;
    }
}

impl<const M: u32> SubAssign for ModInt<{ M }> {
    fn sub_assign(&mut self, rhs: Self) {
        *self = *self - rhs;
    }
}

impl<const M: u32> MulAssign for ModInt<{ M }> {
    fn mul_assign(&mut self, rhs: Self) {
        *self = *self * rhs;
    }
}

impl<const M: u32> DivAssign for ModInt<{ M }> {
    fn div_assign(&mut self, rhs: Self) {
        *self = *self / rhs;
    }
}

impl<const M: u32> Neg for ModInt<{ M }> {
    type Output = Self;
    fn neg(self) -> Self::Output {
        if self.0 == 0 {
            self
        } else {
            Self(M - self.0)
        }
    }
}

impl<const M: u32> std::fmt::Display for ModInt<{ M }> {
    fn fmt<'a>(&self, f: &mut std::fmt::Formatter<'a>) -> std::fmt::Result {
        write!(f, "{}", self.get())
    }
}

impl<const M: u32> std::fmt::Debug for ModInt<{ M }> {
    fn fmt<'a>(&self, f: &mut std::fmt::Formatter<'a>) -> std::fmt::Result {
        write!(f, "{}", self.get())
    }
}

impl<const M: u32> std::str::FromStr for ModInt<{ M }> {
    type Err = std::num::ParseIntError;
    fn from_str(s: &str) -> Result<Self, Self::Err> {
        let val = s.parse::<u32>()?;
        Ok(ModInt::new(val))
    }
}

impl<const M: u32> From<usize> for ModInt<{ M }> {
    fn from(val: usize) -> ModInt<{ M }> {
        ModInt::new((val % M as usize) as u32)
    }
}
// ---------- end modint ----------
// ---------- begin precalc ----------
pub struct Precalc<const MOD: u32> {
    fact: Vec<ModInt<MOD>>,
    ifact: Vec<ModInt<MOD>>,
    inv: Vec<ModInt<MOD>>,
}

impl<const MOD: u32> Precalc<MOD> {
    pub fn new(size: usize) -> Self {
        let mut fact = vec![ModInt::one(); size + 1];
        let mut ifact = vec![ModInt::one(); size + 1];
        let mut inv = vec![ModInt::one(); size + 1];
        for i in 2..=size {
            fact[i] = fact[i - 1] * ModInt::from(i);
        }
        ifact[size] = fact[size].inv();
        for i in (2..=size).rev() {
            inv[i] = ifact[i] * fact[i - 1];
            ifact[i - 1] = ifact[i] * ModInt::from(i);
        }
        Self { fact, ifact, inv }
    }
    pub fn fact(&self, n: usize) -> ModInt<MOD> {
        self.fact[n]
    }
    pub fn ifact(&self, n: usize) -> ModInt<MOD> {
        self.ifact[n]
    }
    pub fn inv(&self, n: usize) -> ModInt<MOD> {
        assert!(0 < n);
        self.inv[n]
    }
    pub fn perm(&self, n: usize, k: usize) -> ModInt<MOD> {
        if k > n {
            return ModInt::zero();
        }
        self.fact[n] * self.ifact[n - k]
    }
    pub fn binom(&self, n: usize, k: usize) -> ModInt<MOD> {
        if n < k {
            return ModInt::zero();
        }
        self.fact[n] * self.ifact[k] * self.ifact[n - k]
    }
}
// ---------- end precalc ----------

impl<const M: u32> Zero for ModInt<{ M }> {
    fn zero() -> Self {
        Self::zero()
    }
    fn is_zero(&self) -> bool {
        self.0 == 0
    }
}

impl<const M: u32> One for ModInt<{ M }> {
    fn one() -> Self {
        Self::one()
    }
    fn is_one(&self) -> bool {
        self.get() == 1
    }
}

impl<const M: u32> Ring for ModInt<{ M }> {}
impl<const M: u32> Field for ModInt<{ M }> {}

// ---------- begin array op ----------

struct NTTPrecalc<const M: u32> {
    sum_e: [ModInt<{ M }>; 30],
    sum_ie: [ModInt<{ M }>; 30],
}

impl<const M: u32> NTTPrecalc<{ M }> {
    const fn new() -> Self {
        let cnt2 = (M - 1).trailing_zeros() as usize;
        let root = ModInt::new(ModInt::<{ M }>::PRIMITIVE_ROOT);
        let zeta = root.pow((M - 1) as u64 >> cnt2);
        let mut es = [ModInt::zero(); 30];
        let mut ies = [ModInt::zero(); 30];
        let mut sum_e = [ModInt::zero(); 30];
        let mut sum_ie = [ModInt::zero(); 30];
        let mut e = zeta;
        let mut ie = e.inv();
        let mut i = cnt2;
        while i >= 2 {
            es[i - 2] = e;
            ies[i - 2] = ie;
            e = e.const_mul(e);
            ie = ie.const_mul(ie);
            i -= 1;
        }
        let mut now = ModInt::one();
        let mut inow = ModInt::one();
        let mut i = 0;
        while i < cnt2 - 1 {
            sum_e[i] = es[i].const_mul(now);
            sum_ie[i] = ies[i].const_mul(inow);
            now = ies[i].const_mul(now);
            inow = es[i].const_mul(inow);
            i += 1;
        }
        Self { sum_e, sum_ie }
    }
}

struct NTTPrecalcHelper<const MOD: u32>;
impl<const MOD: u32> NTTPrecalcHelper<MOD> {
    const A: NTTPrecalc<MOD> = NTTPrecalc::new();
}

pub trait ArrayAdd {
    type Item;
    fn add(&self, rhs: &[Self::Item]) -> Vec<Self::Item>;
}

impl<T> ArrayAdd for [T]
where
    T: Zero + Copy,
{
    type Item = T;
    fn add(&self, rhs: &[Self::Item]) -> Vec<Self::Item> {
        let mut c = vec![T::zero(); self.len().max(rhs.len())];
        c[..self.len()].copy_from_slice(self);
        c.add_assign(rhs);
        c
    }
}

pub trait ArrayAddAssign {
    type Item;
    fn add_assign(&mut self, rhs: &[Self::Item]);
}

impl<T> ArrayAddAssign for [T]
where
    T: Add<Output = T> + Copy,
{
    type Item = T;
    fn add_assign(&mut self, rhs: &[Self::Item]) {
        assert!(self.len() >= rhs.len());
        self.iter_mut().zip(rhs).for_each(|(x, a)| *x = *x + *a);
    }
}

impl<T> ArrayAddAssign for Vec<T>
where
    T: Zero + Add<Output = T> + Copy,
{
    type Item = T;
    fn add_assign(&mut self, rhs: &[Self::Item]) {
        if self.len() < rhs.len() {
            self.resize(rhs.len(), T::zero());
        }
        self.as_mut_slice().add_assign(rhs);
    }
}

pub trait ArraySub {
    type Item;
    fn sub(&self, rhs: &[Self::Item]) -> Vec<Self::Item>;
}

impl<T> ArraySub for [T]
where
    T: Zero + Sub<Output = T> + Copy,
{
    type Item = T;
    fn sub(&self, rhs: &[Self::Item]) -> Vec<Self::Item> {
        let mut c = vec![T::zero(); self.len().max(rhs.len())];
        c[..self.len()].copy_from_slice(self);
        c.sub_assign(rhs);
        c
    }
}

pub trait ArraySubAssign {
    type Item;
    fn sub_assign(&mut self, rhs: &[Self::Item]);
}

impl<T> ArraySubAssign for [T]
where
    T: Sub<Output = T> + Copy,
{
    type Item = T;
    fn sub_assign(&mut self, rhs: &[Self::Item]) {
        assert!(self.len() >= rhs.len());
        self.iter_mut().zip(rhs).for_each(|(x, a)| *x = *x - *a);
    }
}

impl<T> ArraySubAssign for Vec<T>
where
    T: Zero + Sub<Output = T> + Copy,
{
    type Item = T;
    fn sub_assign(&mut self, rhs: &[Self::Item]) {
        if self.len() < rhs.len() {
            self.resize(rhs.len(), T::zero());
        }
        self.as_mut_slice().sub_assign(rhs);
    }
}

pub trait ArrayDot {
    type Item;
    fn dot(&self, rhs: &[Self::Item]) -> Vec<Self::Item>;
}

impl<T> ArrayDot for [T]
where
    T: Mul<Output = T> + Copy,
{
    type Item = T;
    fn dot(&self, rhs: &[Self::Item]) -> Vec<Self::Item> {
        assert!(self.len() == rhs.len());
        self.iter().zip(rhs).map(|p| *p.0 * *p.1).collect()
    }
}

pub trait ArrayDotAssign {
    type Item;
    fn dot_assign(&mut self, rhs: &[Self::Item]);
}

impl<T> ArrayDotAssign for [T]
where
    T: MulAssign + Copy,
{
    type Item = T;
    fn dot_assign(&mut self, rhs: &[Self::Item]) {
        assert!(self.len() == rhs.len());
        self.iter_mut().zip(rhs).for_each(|(x, a)| *x *= *a);
    }
}

pub trait ArrayMul {
    type Item;
    fn mul(&self, rhs: &[Self::Item]) -> Vec<Self::Item>;
}

impl<T> ArrayMul for [T]
where
    T: Zero + One + Copy,
{
    type Item = T;
    fn mul(&self, rhs: &[Self::Item]) -> Vec<Self::Item> {
        if self.is_empty() || rhs.is_empty() {
            return vec![];
        }
        let mut res = vec![T::zero(); self.len() + rhs.len() - 1];
        for (i, a) in self.iter().enumerate() {
            for (res, b) in res[i..].iter_mut().zip(rhs.iter()) {
                *res = *res + *a * *b;
            }
        }
        res
    }
}

// transform でlen=1を指定すればNTTになる
pub trait ArrayConvolution {
    type Item;
    fn transform(&mut self, len: usize);
    fn inverse_transform(&mut self, len: usize);
    fn convolution(&self, rhs: &[Self::Item]) -> Vec<Self::Item>;
}

impl<const M: u32> ArrayConvolution for [ModInt<{ M }>] {
    type Item = ModInt<{ M }>;
    fn transform(&mut self, len: usize) {
        let f = self;
        let n = f.len();
        let k = (n / len).trailing_zeros() as usize;
        assert!(len << k == n);
        assert!(k <= ModInt::<{ M }>::ORDER);
        let pre = &NTTPrecalcHelper::<{ M }>::A;
        for ph in 1..=k {
            let p = len << (k - ph);
            let mut now = ModInt::one();
            for (i, f) in f.chunks_exact_mut(2 * p).enumerate() {
                let (x, y) = f.split_at_mut(p);
                for (x, y) in x.iter_mut().zip(y.iter_mut()) {
                    let l = *x;
                    let r = *y * now;
                    *x = l + r;
                    *y = l - r;
                }
                now *= pre.sum_e[(!i).trailing_zeros() as usize];
            }
        }
    }
    fn inverse_transform(&mut self, len: usize) {
        let f = self;
        let n = f.len();
        let k = (n / len).trailing_zeros() as usize;
        assert!(len << k == n);
        assert!(k <= ModInt::<{ M }>::ORDER);
        let pre = &NTTPrecalcHelper::<{ M }>::A;
        for ph in (1..=k).rev() {
            let p = len << (k - ph);
            let mut inow = ModInt::one();
            for (i, f) in f.chunks_exact_mut(2 * p).enumerate() {
                let (x, y) = f.split_at_mut(p);
                for (x, y) in x.iter_mut().zip(y.iter_mut()) {
                    let l = *x;
                    let r = *y;
                    *x = l + r;
                    *y = (l - r) * inow;
                }
                inow *= pre.sum_ie[(!i).trailing_zeros() as usize];
            }
        }
        let ik = ModInt::new(2).inv().pow(k as u64);
        for f in f.iter_mut() {
            *f *= ik;
        }
    }
    fn convolution(&self, rhs: &[Self::Item]) -> Vec<Self::Item> {
        if self.len().min(rhs.len()) <= 32 {
            return self.mul(rhs);
        }
        const PARAM: usize = 10;
        let size = self.len() + rhs.len() - 1;
        let mut k = 0;
        while (size + (1 << k) - 1) >> k > PARAM {
            k += 1;
        }
        let len = (size + (1 << k) - 1) >> k;
        let mut f = vec![ModInt::zero(); len << k];
        let mut g = vec![ModInt::zero(); len << k];
        f[..self.len()].copy_from_slice(self);
        g[..rhs.len()].copy_from_slice(rhs);
        f.transform(len);
        g.transform(len);
        let mut buf = [ModInt::zero(); 2 * PARAM - 1];
        let buf = &mut buf[..(2 * len - 1)];
        let pre = &NTTPrecalcHelper::<{ M }>::A;
        let mut now = ModInt::one();
        for (i, (f, g)) in f
            .chunks_exact_mut(2 * len)
            .zip(g.chunks_exact(2 * len))
            .enumerate()
        {
            let mut r = now;
            for (f, g) in f.chunks_exact_mut(len).zip(g.chunks_exact(len)) {
                buf.fill(ModInt::zero());
                for (i, f) in f.iter().enumerate() {
                    for (buf, g) in buf[i..].iter_mut().zip(g.iter()) {
                        *buf = *buf + *f * *g;
                    }
                }
                f.copy_from_slice(&buf[..len]);
                for (f, buf) in f.iter_mut().zip(buf[len..].iter()) {
                    *f = *f + r * *buf;
                }
                r = -r;
            }
            now *= pre.sum_e[(!i).trailing_zeros() as usize];
        }
        f.inverse_transform(len);
        f.truncate(self.len() + rhs.len() - 1);
        f
    }
}
// ---------- end array op ----------

pub fn subset_convolution<T>(a: &[T], b: &[T]) -> Vec<T>
where
    T: Ring + Copy,
{
    let size = a.len().next_power_of_two();
    assert!(size > 0 && a.len() == size && b.len() == size);
    let n = size.trailing_zeros() as usize;
    let mut x = vec![T::zero(); (n + 1) << n];
    let mut y = vec![T::zero(); (n + 1) << n];
    for (x, a) in [(&mut x, a), (&mut y, b)].iter_mut() {
        for (i, (x, a)) in x.chunks_exact_mut(n + 1).zip(a.iter()).enumerate() {
            x[i.count_ones() as usize] = *a;
        }
    }
    //    #[target_feature(enable = "avx2")]
    unsafe fn rec<T>(x: &mut [T], y: &mut [T], len: usize, cnt: usize)
    where
        T: Ring + Copy,
    {
        if x.len() == len {
            let mut buf = [T::zero(); 21];
            let buf = &mut buf[..len];
            let a = &x[..=cnt];
            let b = &y[..=cnt];
            for (i, x) in a.iter().enumerate() {
                let g = cnt - i;
                for (buf, y) in buf[(i + g)..].iter_mut().zip(b[g..].iter()) {
                    *buf = *buf + *x * *y;
                }
            }
            x.copy_from_slice(buf);
            return;
        }
        let m = x.len() / 2;
        let (a, b) = x.split_at_mut(m);
        let (c, d) = y.split_at_mut(m);
        let ba = b.iter_mut().zip(a.iter());
        let dc = d.iter_mut().zip(c.iter());
        for ((b, a), (d, c)) in ba.zip(dc) {
            *b = *b + *a;
            *d = *d + *c;
        }
        rec(a, c, len, cnt);
        rec(b, d, len, cnt + 1);
        for (b, a) in b.iter_mut().zip(a.iter()) {
            *b = *b - *a;
        }
    }
    unsafe {
        rec(&mut x, &mut y, n + 1, 0);
    }
    x.chunks_exact(n + 1)
        .enumerate()
        .map(|(i, x)| x[i.count_ones() as usize])
        .collect()
}

这程序好像有点Bug,我给组数据试试?

Details

Tip: Click on the bar to expand more detailed information

Test #1:

score: 100
Accepted
time: 0ms
memory: 2220kb

input:

5 5
3 5
1 4
2 3
2 2
2 1

output:

9 4

result:

ok 2 number(s): "9 4"

Test #2:

score: 0
Accepted
time: 60ms
memory: 13588kb

input:

18 10000000
956231 904623
1692946 1796774
1081323 1170319
3218792 2542661
3183376 3037270
1869132 1442561
35436 35018
1564635 1939950
1847344 2006043
755870 899310
1671882 2057413
1369264 1338951
3132483 3504034
2056224 1825640
1840949 1562071
1514040 1405352
2300821 2421801
2466540 3004920

output:

9391997 70

result:

ok 2 number(s): "9391997 70"

Test #3:

score: 0
Accepted
time: 301ms
memory: 52344kb

input:

20 10000000
1289384 1416015
1692778 1966748
1747794 1708650
2885387 2925290
2516650 2410838
2202363 2092667
368691 407497
1897764 1902790
180541 224758
1089173 1075924
2005212 1743637
702568 566295
465783 369143
2722863 2902398
174068 150211
513930 519657
1634023 1313239
1133070 1040937
961394 11066...

output:

6331196 89

result:

ok 2 number(s): "6331196 89"

Test #4:

score: 0
Accepted
time: 847ms
memory: 106532kb

input:

21 10000000
1432782 1230128
1693282 1456826
605524 521515
2742745 3427204
2231114 2129928
2345527 2397808
511783 521160
2041234 2313965
2323807 2603481
1232121 1410811
719508 850004
416942 495559
2180169 2579591
1580089 1786914
2317568 2292171
1514260 1143717
1348703 1495001
562052 525544
2818854 23...

output:

9336572 5

result:

ok 2 number(s): "9336572 5"

Test #5:

score: 0
Accepted
time: 1803ms
memory: 218924kb

input:

22 10000000
1562592 1176882
1693226 1513484
2293770 2757728
2612851 3010518
1971354 2392268
2475363 2035487
641627 684375
2171036 2181775
1544541 1633457
1361981 1060447
2277948 2792254
157192 141039
1011327 1139897
541119 577682
1538276 1451191
2423314 2061841
1088919 1154927
42526 43789
1779858 16...

output:

8019829 516

result:

ok 2 number(s): "8019829 516"

Test #6:

score: 0
Accepted
time: 1645ms
memory: 219080kb

input:

22 50000000
9900000 50000000
9800000 50000000
9700000 50000000
9600000 50000000
9500000 50000000
9400000 50000000
9300000 50000000
9200000 50000000
9100000 50000000
9190000 50000000
9180000 50000000
9170000 50000000
9160000 50000000
9150000 50000000
9140000 50000000
9130000 50000000
9120000 50000000...

output:

250000000 659827482

result:

ok 2 number(s): "250000000 659827482"

Test #7:

score: 0
Accepted
time: 1233ms
memory: 218924kb

input:

22 49989999
9515787 13633636
7804670 14201704
4490825 15337840
10846676 15905908
4649834 16473976
13564408 17042044
26330177 17610112
31079612 18178180
9508811 18746248
11012937 19314316
9221231 19882384
35630511 20450452
33570222 21018520
33987302 22154656
28961982 22722724
29610359 23290792
342743...

output:

297099616 239005143

result:

ok 2 number(s): "297099616 239005143"

Test #8:

score: 0
Accepted
time: 1694ms
memory: 218980kb

input:

22 49889999
4418358 4535448
7690530 4724425
3667793 4913402
8304776 5102379
2539846 5291356
2404119 5480333
2368750 5669310
3896314 5858287
6349833 6047264
10839169 6425218
10867512 6614195
9018761 6803172
5396983 6992149
2026994 7181126
6093366 7370103
10403853 7559080
5578332 7748057
13492459 7937...

output:

28157573 762

result:

ok 2 number(s): "28157573 762"

Test #9:

score: 0
Accepted
time: 1646ms
memory: 218888kb

input:

22 48889995
670320 2222256
1480754 2407444
2099421 2592632
3936255 2777820
959515 2963008
4781765 3333384
5446683 3518572
1207621 3703760
5965481 3888948
5353960 4074136
3991352 4259324
3814761 4629700
7642867 4814888
6776227 5000076
7737927 5185264
6271909 5370452
8235670 5555640
5720862 5740828
94...

output:

15926168 295

result:

ok 2 number(s): "15926168 295"

Test #10:

score: 0
Accepted
time: 1598ms
memory: 218972kb

input:

22 48889995
3609129 2222256
4285697 2407444
1507969 2592632
1231013 2777820
3176763 2963008
3473072 3148196
7482780 3518572
2891596 3703760
8705206 3888948
7267923 4074136
7325365 4259324
2847372 4444512
5957854 4629700
6070319 4814888
5000188 5000076
6651643 5185264
4854109 5370452
5385621 5555640
...

output:

15000228 109

result:

ok 2 number(s): "15000228 109"

Test #11:

score: 0
Accepted
time: 1712ms
memory: 218936kb

input:

22 48889995
1216303 2222260
1359130 2415500
3584343 2608740
5573601 2801980
6497030 2995220
961106 3188460
7210397 3381700
7437984 3574940
3653310 3768180
8153230 3961420
9078129 4154660
9339995 4347900
9546227 4541140
5979651 4927620
8415111 5120860
2355876 5314100
5268961 5507340
5513979 5700580
5...

output:

14976100 7

result:

ok 2 number(s): "14976100 7"

Test #12:

score: 0
Accepted
time: 1571ms
memory: 219120kb

input:

22 48579995
995517 4416345
4162361 4608360
689494 4800375
1751672 4992390
3152622 5184405
6822783 5376420
9853978 5568435
8144298 5760450
403922 5952465
4762546 6144480
96738 6336495
3332168 6528510
3046767 6720525
612840 6912540
12718394 7104555
12544817 7296570
932656 7488585
13902077 7680600
1518...

output:

21505680 2766

result:

ok 2 number(s): "21505680 2766"

Test #13:

score: 0
Accepted
time: 1559ms
memory: 218880kb

input:

22 48579995
1487345 4416345
2506907 4608360
4972266 4800375
5406373 4992390
7889100 5184405
9894143 5376420
3260719 5568435
3583436 5760450
2820541 5952465
8370133 6144480
491071 6336495
2885341 6528510
2489830 6720525
2929470 6912540
6880314 7296570
4020302 7488585
1341652 7680600
13092883 7872615
...

output:

21889710 2841

result:

ok 2 number(s): "21889710 2841"

Test #14:

score: 0
Accepted
time: 1700ms
memory: 218972kb

input:

22 48579995
2167618 4416345
8701572 4608360
8901658 4800375
2606668 4992390
10331331 5184405
473563 5376420
9425532 5568435
2521056 5760450
7409167 5952465
5163980 6144480
11569213 6336495
2178000 6528510
3109142 6720525
9789269 6912540
4418312 7104555
4345642 7296570
8296204 7680600
7135437 7872615...

output:

21121650 8

result:

ok 2 number(s): "21121650 8"

Test #15:

score: 0
Accepted
time: 1648ms
memory: 218920kb

input:

22 48579995
185663 4416345
6058344 4608360
331879 4800375
1065291 4992390
8966703 5184405
8105358 5376420
5217326 5568435
8799150 5760450
9027629 5952465
8032986 6144480
4436166 6336495
12199531 6528510
8750754 6720525
82844 7104555
1853547 7296570
5898163 7488585
1934865 7680600
1839565 7872615
633...

output:

20545605 26

result:

ok 2 number(s): "20545605 26"

Test #16:

score: 0
Accepted
time: 1634ms
memory: 218924kb

input:

22 48579995
15151 4416345
734549 4608360
7319925 4800375
2129913 4992390
853818 5376420
10141848 5568435
767573 5760450
3980988 5952465
3315870 6144480
2531255 6336495
5624435 6528510
6571293 6720525
40928 6912540
10363672 7104555
1284631 7296570
14701697 7488585
14642456 7680600
322573 7872615
1043...

output:

21697695 4991

result:

ok 2 number(s): "21697695 4991"

Test #17:

score: 0
Accepted
time: 1554ms
memory: 219076kb

input:

22 49898989
7739655 4536267
3933324 4733496
8591811 4930725
9087440 5325183
7835571 5522412
4318275 5719641
4661526 5916870
4200111 6114099
5057614 6311328
921304 6508557
4668507 6705786
5557323 6903015
4273093 7100244
6563270 7297473
9919216 7494702
3400922 7691931
11079804 7889160
100670 8086389
1...

output:

20906274 1

result:

ok 2 number(s): "20906274 1"

Test #18:

score: 0
Accepted
time: 1236ms
memory: 219076kb

input:

22 49898989
6061313 4536267
716781 4733496
305819 4930725
6315187 5127954
4257670 5325183
2230859 5522412
1085663 5719641
5327241 5916870
1902077 6114099
4171313 6311328
10963222 6508557
1747036 6903015
10948695 7100244
3677364 7297473
11817601 7494702
11781634 7691931
3295539 7889160
1325434 808638...

output:

20511816 50

result:

ok 2 number(s): "20511816 50"

Test #19:

score: 0
Accepted
time: 1331ms
memory: 218896kb

input:

22 49898979
1647035 4536250
175922 4717700
8292866 4899150
2096187 5080600
10066004 5262050
961380 5443500
1647976 5624950
5110920 5987850
2028528 6169300
8462757 6713650
1216165 6895100
1260925 7076550
8167307 7258000
7304251 7439450
11040257 7620900
5536709 7802350
4725071 7983800
3148347 8165250
...

output:

21592550 54

result:

ok 2 number(s): "21592550 54"

Test #20:

score: 0
Accepted
time: 1356ms
memory: 218924kb

input:

22 49898919
4880960 3402175
5824531 3674349
2692142 3810436
219059 3946523
3955872 4082610
1597316 4354784
6797847 4490871
1286029 4626958
3989070 4763045
6096677 4899132
6378309 5035219
3025127 5171306
7099640 5307393
9936888 5443480
7942273 5579567
5288035 5715654
6910366 5851741
588733 5987828
88...

output:

15377831 2

result:

ok 2 number(s): "15377831 2"

Test #21:

score: 0
Accepted
time: 1252ms
memory: 218976kb

input:

22 49898919
5878918 3066492
6028670 3184434
1748377 3302376
3583403 3420318
61448 3538260
4692284 3656202
5129355 3774144
6440565 4010028
1002813 4127970
1728560 4245912
4721603 4363854
6446718 4481796
4118552 4599738
4479205 4717680
8610916 4835622
63195 4953564
9769813 5071506
5123156 5189448
4790...

output:

13445388 2

result:

ok 2 number(s): "13445388 2"

Test #22:

score: 0
Accepted
time: 1237ms
memory: 218920kb

input:

22 49898919
4757745 2721750
1190291 2830620
122673 2939490
5285455 3048360
5154097 3157230
3426786 3266100
2776798 3374970
6808419 3483840
7113299 3592710
4948131 3701580
4444440 3810450
1054709 3919320
4310982 4028190
8200366 4137060
1136653 4245930
4064806 4354800
3259693 4463670
5015241 4572540
8...

output:

12084570 61

result:

ok 2 number(s): "12084570 61"

Test #23:

score: 0
Accepted
time: 1212ms
memory: 218896kb

input:

22 49898919
4700657 2598900
3031551 2702856
2474511 2806812
5253209 2910768
4420840 3014724
5145346 3118680
2600255 3222636
1962472 3326592
6224012 3430548
2681629 3534504
2745527 3638460
5992867 3742416
2067411 3846372
6330981 3950328
5060577 4054284
6543128 4262196
5788423 4366152
5569899 4470108
...

output:

11435160 17

result:

ok 2 number(s): "11435160 17"

Test #24:

score: 0
Accepted
time: 1255ms
memory: 218884kb

input:

22 49898919
3161907 2948554
1025254 3076752
5761371 3204950
508930 3333148
4685707 3461346
5326061 3589544
5702566 3717742
6533903 3845940
4153649 4102336
1132247 4230534
8560233 4358732
8679182 4486930
4205825 4615128
739891 4743326
7020873 4871524
6479109 4999722
5459256 5127920
6220335 5256118
33...

output:

13332592 3

result:

ok 2 number(s): "13332592 3"

Test #25:

score: 0
Accepted
time: 1238ms
memory: 218976kb

input:

22 49998920
5432634 2499936
863708 2604100
2752108 2708264
5483524 2812428
3143863 2916592
3862668 3020756
3252628 3124920
5204497 3229084
1249648 3333248
3953145 3541576
1507722 3645740
8393362 3749904
6439438 3854068
4362518 3958232
4233238 4062396
5523854 4166560
9201858 4270724
2455377 4374888
8...

output:

11145548 2

result:

ok 2 number(s): "11145548 2"

Test #26:

score: 0
Accepted
time: 1257ms
memory: 218888kb

input:

22 49998920
6166390 2727208
5195387 2851172
2483572 2975136
6640764 3099100
2033798 3223064
5969501 3347028
7968425 3470992
857128 3594956
6854182 3718920
2064030 3842884
8893787 3966848
8849735 4090812
743604 4214776
2540982 4338740
7410235 4462704
2247651 4586668
785337 4710632
8843312 4834596
508...

output:

12024508 5

result:

ok 2 number(s): "12024508 5"

Test #27:

score: 0
Accepted
time: 1271ms
memory: 218900kb

input:

22 49998920
1851866 2499926
1743639 2613559
58569 2727192
6420362 2840825
3807544 2954458
2258556 3068091
7054799 3181724
3607029 3295357
5664438 3408990
7048880 3522623
6084252 3636256
4253765 3749889
3691283 3863522
4746341 3977155
4213709 4090788
5646732 4204421
8240035 4318054
9886432 4431687
48...

output:

11249667 4

result:

ok 2 number(s): "11249667 4"

Test #28:

score: 0
Accepted
time: 1525ms
memory: 219048kb

input:

22 15
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1
2 1

output:

4 736056326

result:

ok 2 number(s): "4 736056326"

Test #29:

score: 0
Accepted
time: 952ms
memory: 219088kb

input:

22 50000000
25000001 100001
25000002 100002
25000003 100003
1 10001
2 10002
3 10003
4 10004
5 10005
6 10006
7 10007
8 10008
9 10009
10 10010
11 10011
12 10012
13 10013
14 10014
15 10015
16 10016
17 10017
18 10018
19 10019

output:

300006 164017114

result:

ok 2 number(s): "300006 164017114"

Extra Test:

score: 0
Extra Test Passed