Skip to content

Commit

Permalink
past202109 l
Browse files Browse the repository at this point in the history
  • Loading branch information
bouzuya committed Jan 25, 2022
1 parent 774a27a commit ab34e4d
Showing 1 changed file with 27 additions and 3 deletions.
30 changes: 27 additions & 3 deletions past202109-open/src/bin/l.rs
@@ -1,10 +1,34 @@
use proconio::{input, marker::Usize1};
use proconio::input;
use superslice::Ext;

fn main() {
input! {
n: usize,
a: [Usize1; n],
k: usize,
a: [i64; n],
};
let ans = n - a.len();
let mut s = std::iter::once(0)
.chain(a.iter().scan(0, |acc, &i| {
*acc += i;
Some(*acc)
}))
.collect::<Vec<i64>>();
s.sort();

let mut ng = -1_i64;
let mut ok = 1 << 60;
while ok - ng > 1 {
let x = ng + (ok - ng) / 2;
let mut count = 0;
for (i, s_i) in s.iter().copied().enumerate() {
count += s[i + 1..].upper_bound(&(s_i + x));
}
if count >= k {
ok = x;
} else {
ng = x;
}
}
let ans = ok;
println!("{}", ans);
}

0 comments on commit ab34e4d

Please sign in to comment.