Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save akiradeveloper/4b026457879c780a46d3584829e1e952 to your computer and use it in GitHub Desktop.
Save akiradeveloper/4b026457879c780a46d3584829e1e952 to your computer and use it in GitHub Desktop.
典型11WA WHY
// https://atcoder.jp/contests/typical90/tasks/typical90_k
fn solve() {
let out = stdout();
let mut out = BufWriter::new(out.lock());
input!{
n:usize,
dcs:[(usize,usize,i64);n],
}
let mut dcs=dcs; dcs.sort_by_key(|x|x.0);
// [見た個数][仕事時間]
let mut dp = dvec![-1;5001,5001];
dp[0][0]=0;
for i in 0..n {
let (d,c,s) = dcs[i];
for j in 0..5001 {
if dp[i][j] == -1 {
continue;
}
let nexj = j+c;
if nexj > 5000 {
continue;
}
if nexj <= d {
// iをやる
chmax!(dp[i+1][nexj], dp[i][j]+s);
// iをやらない
chmax!(dp[i+1][j], dp[i][j]);
} else {
// iは出来ない
chmax!(dp[i+1][j], dp[i][j]);
}
}
}
let mut maxv=0;
for j in 0..5001 {
chmax!(maxv,dp[n][j]);
}
println!("{}",maxv);
}
@akiradeveloper
Copy link
Author

自力解決した。
if nexj > 5000のチェックをここでするのがおかしい。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment