Submission #2149616
Source Code Expand
/** * _ _ __ _ _ _ _ _ _ _ * | | | | / / | | (_) | (_) | | (_) | | * | |__ __ _| |_ ___ ___ / /__ ___ _ __ ___ _ __ ___| |_ _| |_ ___ _____ ______ _ __ _ _ ___| |_ ______ ___ _ __ _ _ __ _ __ ___| |_ ___ * | '_ \ / _` | __/ _ \ / _ \ / / __/ _ \| '_ ` _ \| '_ \ / _ \ __| | __| \ \ / / _ \______| '__| | | / __| __|______/ __| '_ \| | '_ \| '_ \ / _ \ __/ __| * | | | | (_| | || (_) | (_) / / (_| (_) | | | | | | |_) | __/ |_| | |_| |\ V / __/ | | | |_| \__ \ |_ \__ \ | | | | |_) | |_) | __/ |_\__ \ * |_| |_|\__,_|\__\___/ \___/_/ \___\___/|_| |_| |_| .__/ \___|\__|_|\__|_| \_/ \___| |_| \__,_|___/\__| |___/_| |_|_| .__/| .__/ \___|\__|___/ * | | | | | | * |_| |_| |_| * * https://github.com/hatoo/competitive-rust-snippets */ #[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, stdout, BufWriter, Write}; mod util { use std::io::{stdin, stdout, BufWriter, StdoutLock}; 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 chars() -> Vec<char> { line().chars().collect() } #[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(dead_code)] pub fn with_bufwriter<F: FnOnce(BufWriter<StdoutLock>) -> ()>(f: F) { let out = stdout(); let writer = BufWriter::new(out.lock()); f(writer) } } #[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 < _ >> ( ) } } ; ( $ t : ty ;; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ;; ) ) . collect ::< Vec < _ >> ( ) } ; } #[allow(unused_macros)] macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { println ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } } #[allow(dead_code)] pub const INF: u64 = 1 << 60; #[allow(dead_code)] fn main() { let n = get!(usize); let mut hp = get!(u64, u64; n); hp.sort_by_key(|&(h, p)| h + p); let mut dp = vec![INF; n + 1]; dp[0] = 0; for (h, p) in hp { for i in (1..n + 1).rev() { if dp[i - 1] <= h { dp[i] = min(dp[i], dp[i - 1] + p); } } } println!("{}", (1..n + 1).filter(|&i| dp[i] != INF).max().unwrap()); }
Submission Info
Submission Time | |
---|---|
Task | D - Zabuton |
User | hatoo |
Language | Rust (1.15.1) |
Score | 700 |
Code Size | 4257 Byte |
Status | AC |
Exec Time | 36 ms |
Memory | 4476 KB |
Judge Result
Set Name | sample | All | ||||
---|---|---|---|---|---|---|
Score / Max Score | 0 / 0 | 700 / 700 | ||||
Status |
|
|
Set Name | Test Cases |
---|---|
sample | sample-01.txt, sample-02.txt, sample-03.txt |
All | sample-01.txt, sample-02.txt, sample-03.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, 01-16.txt, 01-17.txt, 01-18.txt, 01-19.txt, 01-20.txt, 01-21.txt, 01-22.txt, 01-23.txt, 01-24.txt, 01-25.txt, 01-26.txt, 01-27.txt, 01-28.txt, 01-29.txt, 01-30.txt, 01-31.txt, 01-32.txt, 01-33.txt, 01-34.txt, 01-35.txt, 01-36.txt, 01-37.txt, 01-38.txt, 01-39.txt, 01-40.txt, sample-01.txt, sample-02.txt, sample-03.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 | 4 ms | 4352 KB |
01-04.txt | AC | 8 ms | 4352 KB |
01-05.txt | AC | 28 ms | 4352 KB |
01-06.txt | AC | 28 ms | 4352 KB |
01-07.txt | AC | 28 ms | 4352 KB |
01-08.txt | AC | 28 ms | 4352 KB |
01-09.txt | AC | 28 ms | 4352 KB |
01-10.txt | AC | 2 ms | 4352 KB |
01-11.txt | AC | 3 ms | 4352 KB |
01-12.txt | AC | 12 ms | 4352 KB |
01-13.txt | AC | 28 ms | 4352 KB |
01-14.txt | AC | 29 ms | 4476 KB |
01-15.txt | AC | 29 ms | 4352 KB |
01-16.txt | AC | 29 ms | 4352 KB |
01-17.txt | AC | 29 ms | 4352 KB |
01-18.txt | AC | 29 ms | 4352 KB |
01-19.txt | AC | 2 ms | 4352 KB |
01-20.txt | AC | 3 ms | 4352 KB |
01-21.txt | AC | 17 ms | 4352 KB |
01-22.txt | AC | 33 ms | 4352 KB |
01-23.txt | AC | 33 ms | 4352 KB |
01-24.txt | AC | 33 ms | 4352 KB |
01-25.txt | AC | 33 ms | 4352 KB |
01-26.txt | AC | 33 ms | 4352 KB |
01-27.txt | AC | 33 ms | 4352 KB |
01-28.txt | AC | 28 ms | 4352 KB |
01-29.txt | AC | 28 ms | 4352 KB |
01-30.txt | AC | 28 ms | 4352 KB |
01-31.txt | AC | 28 ms | 4352 KB |
01-32.txt | AC | 28 ms | 4352 KB |
01-33.txt | AC | 28 ms | 4352 KB |
01-34.txt | AC | 28 ms | 4352 KB |
01-35.txt | AC | 36 ms | 4352 KB |
01-36.txt | AC | 36 ms | 4352 KB |
01-37.txt | AC | 35 ms | 4352 KB |
01-38.txt | AC | 35 ms | 4352 KB |
01-39.txt | AC | 35 ms | 4352 KB |
01-40.txt | AC | 27 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 |