Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
33 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,41 @@ | ||
use proconio::input; | ||
use proconio::marker::Usize1; | ||
|
||
macro_rules! chmin { | ||
($min_v: expr, $v: expr) => { | ||
if $v < $min_v { | ||
$min_v = $v; | ||
true | ||
} else { | ||
false | ||
} | ||
}; | ||
} | ||
|
||
fn main() { | ||
input! { | ||
n: usize, | ||
a: [Usize1; n], | ||
mut ab: [(usize, usize); n], | ||
}; | ||
let ans = n - a.len(); | ||
ab.sort_by_key(|&(a_i, b_i)| (b_i, a_i)); | ||
|
||
// dp[i][j] := i 番目までで j 個のファーストアクセプタンスのときの最短時間 | ||
let inf = 1_000_000_000; | ||
let mut dp = vec![vec![inf; n + 1]; n + 1]; | ||
dp[0][0] = 0; | ||
for (i, &(a_i, b_i)) in ab.iter().enumerate() { | ||
for j in 0..n { | ||
chmin!(dp[i + 1][j], dp[i][j]); | ||
if dp[i][j] + a_i <= b_i { | ||
chmin!(dp[i + 1][j + 1], dp[i][j + 1]); | ||
chmin!(dp[i + 1][j + 1], dp[i][j] + a_i); | ||
} | ||
} | ||
} | ||
let mut ans = 0; | ||
for (i, &v) in dp[n].iter().enumerate() { | ||
if v != inf { | ||
ans = i; | ||
} | ||
} | ||
println!("{}", ans); | ||
} |