Submission #8375517


Source Code Expand

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { stdin: s.lock() };
    let n: usize = sc.read();
    let mut t: i64 = sc.read();
    let mut time = Vec::<i64>::new();
    let mut mint: i64 = 0;
    for _ in 0 .. n {
        let (a, b) = (sc.read::<i64>(), sc.read::<i64>());
        mint += b;
        time.push(a - b);
    }
    if mint > t {
        println!("-1");
        return;
    }
    t -= mint;
    time.sort();
    let myself = time.iter().scan(0, |r, &x|
        if *r + x <= t {
            *r += x;
            Some(0)
        } else {
            None
        }).count();
    println!("{}", time.len() - myself);
}

pub struct Scanner<R> {
    stdin: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}

Submission Info

Submission Time
Task C - 8月31日
User forar
Language Rust (1.15.1)
Score 100
Code Size 1484 Byte
Status AC
Exec Time 44 ms
Memory 4476 KB

Judge Result

Set Name Sample Dataset1 Dataset2
Score / Max Score 0 / 0 30 / 30 70 / 70
Status
AC × 5
AC × 15
AC × 41
Set Name Test Cases
Sample sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt, sample-05.txt
Dataset1 sample-01, sample-02, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt
Dataset2 sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt, sample-05.txt, 01-01.txt, 01-02.txt, 01-03.txt, 01-04.txt, 01-05.txt, 01-06.txt, 01-07.txt, 01-08.txt, 01-09.txt, 01-10.txt, 01-11.txt, 01-12.txt, 01-13.txt, 01-14.txt, 01-15.txt, 02-01.txt, 02-02.txt, 02-03.txt, 02-04.txt, 02-05.txt, 02-06.txt, 02-07.txt, 02-08.txt, 02-09.txt, 02-10.txt, 02-11.txt, 02-12.txt, 02-13.txt, 02-14.txt, 02-15.txt, 02-16.txt, sample-01.txt, sample-02.txt, sample-03.txt, sample-04.txt, sample-05.txt
Case Name Status Exec Time Memory
01-01.txt AC 2 ms 4352 KB
01-02.txt AC 2 ms 4352 KB
01-03.txt AC 2 ms 4352 KB
01-04.txt AC 2 ms 4352 KB
01-05.txt AC 3 ms 4352 KB
01-06.txt AC 32 ms 4352 KB
01-07.txt AC 30 ms 4352 KB
01-08.txt AC 26 ms 4352 KB
01-09.txt AC 5 ms 4352 KB
01-10.txt AC 12 ms 4352 KB
01-11.txt AC 33 ms 4352 KB
01-12.txt AC 31 ms 4352 KB
01-13.txt AC 32 ms 4352 KB
01-14.txt AC 15 ms 4352 KB
01-15.txt AC 31 ms 4352 KB
02-01.txt AC 2 ms 4352 KB
02-02.txt AC 2 ms 4352 KB
02-03.txt AC 2 ms 4352 KB
02-04.txt AC 2 ms 4352 KB
02-05.txt AC 6 ms 4352 KB
02-06.txt AC 44 ms 4352 KB
02-07.txt AC 44 ms 4352 KB
02-08.txt AC 44 ms 4476 KB
02-09.txt AC 39 ms 4352 KB
02-10.txt AC 43 ms 4352 KB
02-11.txt AC 8 ms 4352 KB
02-12.txt AC 43 ms 4352 KB
02-13.txt AC 38 ms 4352 KB
02-14.txt AC 44 ms 4352 KB
02-15.txt AC 39 ms 4352 KB
02-16.txt AC 38 ms 4352 KB
sample-01.txt AC 2 ms 4352 KB
sample-02.txt AC 2 ms 4352 KB
sample-03.txt AC 2 ms 4352 KB
sample-04.txt AC 2 ms 4352 KB
sample-05.txt AC 2 ms 4352 KB