File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ import sys
2+ input = sys .stdin .readline
3+
4+
5+ def solution ():
6+ n = int (input ())
7+ cranes = list (map (int , input ().split ()))
8+ m = int (input ())
9+ boxes = list (map (int , input ().split ()))
10+ cnt = 0
11+
12+ cranes .sort (reverse = True )
13+ boxes .sort (reverse = True )
14+ crane_pos = [0 ] * n
15+ box_check = [True ] * m
16+ checked = 0
17+ if cranes [0 ] < boxes [0 ]:
18+ print (- 1 )
19+ return
20+ else :
21+ while checked < m :
22+ for i in range (n ):
23+ for j in range (crane_pos [i ], m ):
24+ if box_check [j ] and cranes [i ] >= boxes [j ]:
25+ crane_pos [i ] += 1
26+ box_check [j ] = False
27+ checked += 1
28+ break
29+ crane_pos [i ] += 1
30+ cnt += 1
31+ print (cnt )
32+
33+ solution ()
Original file line number Diff line number Diff line change @@ -52,17 +52,14 @@ func main() {
5252 for i := range crains {
5353 for j := crainPos [i ]; j < m ; j ++ {
5454 if ! boxCheck [j ] && crains [i ] >= boxes [j ] {
55- crainPos [i ] = j + 1
55+ crainPos [i ]++
5656 boxCheck [j ] = true
5757 checked ++
5858 break
5959 }
60+ crainPos [i ]++
6061 }
6162 }
62- if count > 10000 {
63- fmt .Printf ("%d" , - 1 )
64- return
65- }
6663 count ++
6764 }
6865 fmt .Printf ("%d" , count )
You can’t perform that action at this time.
0 commit comments