File tree Expand file tree Collapse file tree 1 file changed +10
-19
lines changed Expand file tree Collapse file tree 1 file changed +10
-19
lines changed Original file line number Diff line number Diff line change @@ -9,31 +9,22 @@ fn main() {
9
9
input ! {
10
10
mut n: usize ,
11
11
m: usize ,
12
- mut ab: [ ( usize , usize ) ; m] ,
12
+ ab: [ ( usize , usize ) ; m] ,
13
13
}
14
14
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 ( ) ;
25
16
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
+ }
31
19
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 ;
33
25
count += x;
34
- n = b ;
26
+ n -= x * d ;
35
27
}
36
28
37
-
38
29
println ! ( "{}" , count) ;
39
30
}
You can’t perform that action at this time.
0 commit comments