Datasets:
Tasks:
Text Generation
Modalities:
Text
Formats:
json
Languages:
English
Size:
< 1K
ArXiv:
Tags:
competitive-programming
code-generation
specification-generation
proof-generation
verification
rust
License:
File size: 2,182 Bytes
b1eb0dd | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 | impl Solution {
pub fn overlaps_window(start: i32, d: i32, l: i32, r: i32) -> bool
{
(start as i64) <= (r as i64) && (l as i64) <= (start as i64) + (d as i64) - 1
}
pub fn overlap_count(start: i32, d: i32, left: &Vec<i32>, right: &Vec<i32>) -> i32
{
let mut cnt: i32 = 0;
let mut j: usize = 0;
while j < left.len()
{
if Self::overlaps_window(start, d, left[j], right[j]) {
cnt = cnt + 1;
}
j = j + 1;
}
cnt
}
pub fn best_start_days(n: i32, d: i32, left: Vec<i32>, right: Vec<i32>) -> (i32, i32)
{
let m = n - d + 1;
let mm = m as usize;
let mut diff: Vec<i32> = Vec::with_capacity(mm + 2);
let mut p: usize = 0;
while p < mm + 2
{
diff.push(0);
p += 1;
}
let mut j: usize = 0;
while j < left.len()
{
let l = left[j];
let r = right[j];
let lo = if l - d + 1 > 1 { l - d + 1 } else { 1 };
let hi = if r < m { r } else { m };
if lo <= hi {
let li = lo as usize;
let hi1 = (hi + 1) as usize;
diff[li] = diff[li] + 1;
diff[hi1] = diff[hi1] - 1;
}
j += 1;
}
let mut best_bro: i32 = 1;
let mut best_mom: i32 = 1;
let mut best_bro_count: i32 = i32::MIN;
let mut best_mom_count: i32 = i32::MAX;
let mut cur: i32 = 0;
let mut start: usize = 1;
while start <= mm
{
cur += diff[start];
let old_best_bro = best_bro;
let old_best_mom = best_mom;
let old_best_bro_count = best_bro_count;
let old_best_mom_count = best_mom_count;
if cur > best_bro_count {
best_bro_count = cur;
best_bro = start as i32;
}
if cur < best_mom_count {
best_mom_count = cur;
best_mom = start as i32;
}
start += 1;
}
(best_bro, best_mom)
}
}
|