結果
| 問題 | No.1583 Building Blocks | 
| コンテスト | |
| ユーザー |  ikd | 
| 提出日時 | 2021-07-03 10:56:30 | 
| 言語 | Rust (1.83.0 + proconio) | 
| 結果 | 
                                WA
                                 
                             | 
| 実行時間 | - | 
| コード長 | 2,278 bytes | 
| コンパイル時間 | 14,175 ms | 
| コンパイル使用メモリ | 380,108 KB | 
| 実行使用メモリ | 9,856 KB | 
| 最終ジャッジ日時 | 2024-06-30 03:25:01 | 
| 合計ジャッジ時間 | 16,087 ms | 
| ジャッジサーバーID (参考情報) | judge4 / judge2 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 41 WA * 2 | 
ソースコード
//! # Bundled libraries
//!
//! - `procon_reader 0.1.0 (git+https://github.com/ia7ck/rust-competitive-programming#59eb5cd766b43a170294fe6e7a7026645fc306e3)` licensed under **missing** as `crate::procon_reader`
use procon_reader::ProconReader;
fn main() {
    let stdin = std::io::stdin();
    let mut rd = ProconReader::new(stdin.lock());
    let n: usize = rd.get();
    let ws: Vec<(u64, u64)> = (0..n)
        .map(|_| {
            let w: u64 = rd.get();
            let s: u64 = rd.get();
            (w, s)
        })
        .collect();
    let mut ws = ws;
    ws.sort_by_key(|(w, s)| w + s);
    let inf = std::u64::MAX / 2;
    let mut dp = vec![vec![inf; n + 1]; n + 1];
    dp[0][0] = 0;
    for (i, &(w, s)) in ws.iter().enumerate() {
        for j in 1..=n {
            dp[i + 1][j] = dp[i + 1][j].min(dp[i][j]);
            if s >= dp[i][j - 1] {
                dp[i + 1][j] = dp[i + 1][j].min(dp[i][j - 1] + w);
            }
        }
    }
    let ans = dp[n].iter().rposition(|&x| x != inf).unwrap();
    println!("{}", ans);
}
// The following code was expanded by `cargo-equip`.
#[cfg_attr(any(),rustfmt::skip)]#[allow(unused)]pub mod procon_reader{pub struct ProconReader<R>{r:R,l:String,i:usize,}impl<R:std::io::BufRead>ProconReader<R>{pub fn new(reader:R)->Self{Self{r:reader,l:String::new(),i:0,}}pub fn get<T>(&mut self)->T where T:std::str::FromStr,<T as std::str::FromStr>::Err:std::fmt::Debug,{self.skip_blanks();assert!(self.i<self.l.len());assert_ne!(&self.l[self.i..=self.i]," ");let rest=&self.l[self.i..];let len=rest.find(' ').unwrap_or_else(| |rest.len());let val=rest[..len].parse().unwrap_or_else(|e|panic!("{:?}, attempt to read `{}`",e,rest));self.i+=len;val}fn skip_blanks(&mut self){loop{match self.l[self.i..].find(|ch|ch!=' '){Some(j)=>{self.i+=j;break;}None=>{let mut buf=String::new();let num_bytes=self.r.read_line(&mut buf).unwrap_or_else(|_|panic!("invalid UTF-8"));assert!(num_bytes>0,"reached EOF :(");self.l=buf.trim_end_matches('\n').trim_end_matches('\r').to_string();self.i=0;}}}}pub fn get_vec<T>(&mut self,n:usize)->Vec<T>where T:std::str::FromStr,<T as std::str::FromStr>::Err:std::fmt::Debug,{(0..n).map(|_|self.get()).collect()}pub fn get_chars(&mut self)->Vec<char>{self.get::<String>().chars().collect()}}}
            
            
            
        