Submission #3750692


Source Code Expand

use std::cmp;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { reader: s.lock() };
    let n: usize = sc.read();
    let mut a = vec![];
    let mut b = vec![];
    for _ in 0..n {
        a.push(sc.read::<usize>());
        b.push(sc.read::<usize>());
    }
    let sum = a.iter().sum::<usize>();
    let mut min = sum;
    for i in 0..n {
        if a[i] > b[i] {
            min = cmp::min(min, b[i]);
        }
    }
    if min == sum {
        println!("0");
    } else {
        println!("{}", sum - min);
    }
}

pub struct Scanner<R> {
    reader: 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
            .reader
            .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 read_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 E - Tozan and Gezan
User kenkoooo
Language Rust (1.15.1)
Score 700
Code Size 1379 Byte
Status AC
Exec Time 17 ms
Memory 4352 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 700 / 700
Status
AC × 3
AC × 35
Set Name Test Cases
Sample s1.txt, s2.txt, s3.txt
All 01.txt, 02.txt, 03.txt, 04.txt, 05.txt, 06.txt, 07.txt, 08.txt, 09.txt, 10.txt, 11.txt, 12.txt, 13.txt, 14.txt, 15.txt, 16.txt, 17.txt, 18.txt, 19.txt, 20.txt, 21.txt, 22.txt, 23.txt, 24.txt, 25.txt, 26.txt, 27.txt, 28.txt, 29.txt, 30.txt, 31.txt, 32.txt, s1.txt, s2.txt, s3.txt
Case Name Status Exec Time Memory
01.txt AC 16 ms 4352 KB
02.txt AC 16 ms 4352 KB
03.txt AC 16 ms 4352 KB
04.txt AC 16 ms 4352 KB
05.txt AC 16 ms 4352 KB
06.txt AC 16 ms 4352 KB
07.txt AC 17 ms 4352 KB
08.txt AC 16 ms 4352 KB
09.txt AC 16 ms 4352 KB
10.txt AC 16 ms 4352 KB
11.txt AC 16 ms 4352 KB
12.txt AC 16 ms 4352 KB
13.txt AC 17 ms 4352 KB
14.txt AC 17 ms 4352 KB
15.txt AC 17 ms 4352 KB
16.txt AC 17 ms 4352 KB
17.txt AC 17 ms 4352 KB
18.txt AC 17 ms 4352 KB
19.txt AC 16 ms 4352 KB
20.txt AC 16 ms 4352 KB
21.txt AC 16 ms 4352 KB
22.txt AC 16 ms 4352 KB
23.txt AC 16 ms 4352 KB
24.txt AC 16 ms 4352 KB
25.txt AC 16 ms 4352 KB
26.txt AC 17 ms 4352 KB
27.txt AC 16 ms 4352 KB
28.txt AC 16 ms 4352 KB
29.txt AC 17 ms 4352 KB
30.txt AC 16 ms 4352 KB
31.txt AC 2 ms 4352 KB
32.txt AC 2 ms 4352 KB
s1.txt AC 2 ms 4352 KB
s2.txt AC 2 ms 4352 KB
s3.txt AC 2 ms 4352 KB