Submission #1870853


Source Code Expand

#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
                   ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
                   ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let n = get!(usize);
    let mut aa = util::gets::<u64>();

    aa.sort();
    let sum = aa.iter().sum::<u64>();

    let mut l = 0;
    let mut r = n;

    while l != r {
        let mid = (l + r) / 2;

        let mut s = aa[..mid + 1].iter().sum::<u64>();
        for &x in &aa[mid + 1..] {
            if x <= s * 2 {
                s += x;
            } else {
                break;
            }
        }

        if s == sum {
            r = mid;
        } else {
            l = mid + 1;
        }
    }

    println!("{}", n - l);
}

Submission Info

Submission Time
Task B - Colorful Creatures
User hatoo
Language Rust (1.15.1)
Score 400
Code Size 2749 Byte
Status AC
Exec Time 17 ms
Memory 8444 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 400 / 400
Status
AC × 3
AC × 19
Set Name Test Cases
Sample sample1.txt, sample2.txt, sample3.txt
All sample1.txt, sample2.txt, sample3.txt, in1.txt, in10.txt, in11.txt, in12.txt, in13.txt, in2.txt, in3.txt, in4.txt, in5.txt, in6.txt, in7.txt, in8.txt, in9.txt, sample1.txt, sample2.txt, sample3.txt
Case Name Status Exec Time Memory
in1.txt AC 17 ms 6396 KB
in10.txt AC 6 ms 4352 KB
in11.txt AC 15 ms 6396 KB
in12.txt AC 14 ms 8444 KB
in13.txt AC 15 ms 8444 KB
in2.txt AC 17 ms 6396 KB
in3.txt AC 17 ms 6396 KB
in4.txt AC 17 ms 6396 KB
in5.txt AC 7 ms 4352 KB
in6.txt AC 14 ms 6396 KB
in7.txt AC 17 ms 6396 KB
in8.txt AC 14 ms 6396 KB
in9.txt AC 3 ms 4352 KB
sample1.txt AC 2 ms 4352 KB
sample2.txt AC 2 ms 4352 KB
sample3.txt AC 2 ms 4352 KB