complete 2805.rs 4366.rs 6235.rs 31614.rs 34412.rs

This commit is contained in:
2026-03-30 03:10:37 +09:00
parent 5c6ad569c4
commit c85e661c6c
5 changed files with 148 additions and 0 deletions

View File

@@ -0,0 +1,53 @@
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 m = iter.next().unwrap();
let mut arr = (0..n).map(|_| iter.next().unwrap()).collect::<Vec<_>>();
arr.sort();
let mut lo = 0;
let mut hi = *arr.last().unwrap();
let mut cum = vec![0];
for &e in arr.iter() {
cum.push(cum.last().unwrap() + e);
}
while hi >= lo && hi - lo > 1 {
let mid = (hi + lo) / 2;
let key = arr.binary_search(&mid);
let s = match key {
Ok(idx) => cum[n] - cum[idx] - (n - idx) * mid,
Err(idx) => cum[n] - cum[idx] - (n - idx) * mid,
};
if s < m {
hi = mid - 1;
} else {
if lo == mid {
hi = lo;
}
lo = mid;
}
}
{
let key = arr.binary_search(&hi);
let s = match key {
Ok(idx) => cum[n] - cum[idx] - (n - idx) * hi,
Err(idx) => cum[n] - cum[idx] - (n - idx) * hi,
};
if s >= m {
println!("{}", hi);
} else {
println!("{}", lo);
}
}
}

View File

@@ -0,0 +1,12 @@
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 h = iter.next().unwrap();
let m = iter.next().unwrap();
println!("{}", 60 * h + m);
}

View File

@@ -0,0 +1,10 @@
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 x = iter.next().unwrap();
println!("{}", x + (x >= 13) as usize);
}

View File

@@ -0,0 +1,39 @@
use std::io::stdin;
fn main() {
let mut line = String::new();
let mut distance = 0;
let mut before_time = 0;
let mut speed = 0;
loop {
line.clear();
stdin().read_line(&mut line).unwrap();
if line.trim().is_empty() {
break;
}
let mut iter = line.trim().split(' ');
let mut time_str = iter.next().unwrap().split(':');
let (h, m, s) = (
time_str.next().unwrap().parse::<u64>().unwrap(),
time_str.next().unwrap().parse::<u64>().unwrap(),
time_str.next().unwrap().parse::<u64>().unwrap(),
);
let time = h * 3600 + m * 60 + s;
distance = distance + speed * (time - before_time);
if let Some(spd_str) = iter.next() {
speed = spd_str.parse::<u64>().unwrap();
} else {
println!(
"{:02}:{:02}:{:02} {:.2} km",
h,
m,
s,
distance as f64 / 3600f64
);
}
before_time = h * 3600 + m * 60 + s;
}
}

View File

@@ -0,0 +1,34 @@
use std::{
cmp::Reverse,
collections::BinaryHeap,
fmt::Binary,
io::{read_to_string, stdin},
};
fn main() {
let mut line = String::new();
let mut heap = BinaryHeap::new();
loop {
line.clear();
stdin().read_line(&mut line).unwrap();
if line.starts_with('#') {
break;
}
let mut iter = line.trim().split(' ');
iter.next();
let q = iter.next().unwrap().parse::<usize>().unwrap();
let p = iter.next().unwrap().parse::<usize>().unwrap();
heap.push(Reverse((p, q, p)))
}
line.clear();
stdin().read_line(&mut line).unwrap();
let k = line.trim().parse::<usize>().unwrap();
for i in 0..k {
let (curr, q, period) = (heap.pop().unwrap()).0;
heap.push(Reverse((curr + period, q, period)));
println!("{}", q);
}
}