Skip to content

Commit 1466229

Browse files
committed
fix abc415d.rs
1 parent 2b5fe1c commit 1466229

File tree

1 file changed

+10
-19
lines changed

1 file changed

+10
-19
lines changed

src/abc/abc415d.rs

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,31 +9,22 @@ fn main() {
99
input! {
1010
mut n:usize,
1111
m:usize,
12-
mut ab:[(usize, usize);m],
12+
ab:[(usize, usize);m],
1313
}
1414

15-
ab.sort_by(|a, b| {
16-
let v = (a.0-a.1).cmp(&(b.0-b.1));
17-
if v == Ordering::Equal {
18-
a.1.cmp(&b.1).reverse()
19-
} else {
20-
v
21-
}
22-
});
23-
// println!("{:?}", &ab);
24-
let mut count = 0;
15+
let mut que = Vec::new();
2516
for (a,b) in ab {
26-
if a > n {
27-
continue;
28-
}
29-
let diff = a - b;
30-
let base_num = n - a;
17+
que.push((a-b, a, b));
18+
}
3119

32-
let x = 1 + base_num / diff;
20+
que.sort();
21+
let mut count = 0;
22+
for (d,a,_b) in que {
23+
if a > n { continue }
24+
let x = (n-a) / d + 1;
3325
count += x;
34-
n = b;
26+
n -= x * d;
3527
}
3628

37-
3829
println!("{}", count);
3930
}

0 commit comments

Comments
 (0)