complete 15407.rs 24305.rs

This commit is contained in:
2026-04-08 03:53:16 +09:00
parent 31e7805c9f
commit ef49375bfb
2 changed files with 66 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
use std::io::{read_to_string, stdin};
fn main() {
let temp = read_to_string(stdin()).unwrap();
let mut iter = temp
.split_ascii_whitespace()
.map(|x| x.parse::<usize>().unwrap());
let n = iter.next().unwrap();
let mut ta = iter.next().unwrap();
let mut tv = 0;
let mut items = (0..n)
.map(|_| (iter.next().unwrap(), iter.next().unwrap()))
.collect::<Vec<_>>();
items.sort();
while ta > 0 && items.len() > 0 {
let (v, a) = items.pop().unwrap();
if a >= ta {
tv += v * ta;
ta = 0;
} else {
tv += v * a;
ta -= a;
}
}
println!("{}", tv);
}

View File

@@ -0,0 +1,36 @@
use std::io::{read_to_string, stdin};
fn main() {
let temp = read_to_string(stdin()).unwrap();
let mut iter = temp
.split_ascii_whitespace()
.map(|x| x.parse::<usize>().unwrap());
let n = iter.next().unwrap();
let arr = (0..n).map(|i| (i + 1, iter.next().unwrap()));
let mut stack = vec![];
for e in arr {
if stack.is_empty() {
stack.push(e);
print!("{} ", 0);
} else {
while let Some(top) = stack.last() {
if top.1 >= e.1 {
stack.pop();
} else {
break;
}
}
if stack.is_empty() {
stack.push(e);
print!("{} ", 0);
} else {
print!("{} ", stack.last().unwrap().0);
stack.push(e);
}
}
}
}