### 질문에 tc 다통과하는데 왜 틀리는지 모르겠습니다(4,5,6,9,13)

``````public int solution(int bridge_length, int weight, int[] truck_weights) {
int weight_count =0;
int number;
Map<Integer,Integer> map = new HashMap<>();
for(int i=0; i<truck_weights.length; i++){
weight_count += truck_weights[i];
if(!queue.isEmpty()){
number = 0;
for(int y=queue.peek(); y<i; y++){
if(weight_count > weight){
if(number == 0){
number = bridge_length-map.get(queue.peek());
weight_count -= truck_weights[queue.poll()];
}else{
number = bridge_length - (map.get(queue.peek())+number);
weight_count -= truck_weights[queue.poll()];
}
}else{
if(map.get(y) < bridge_length)
map.replace(y,map.get(y)+number+1);
else weight_count -= truck_weights[queue.poll()];
}
}
}
map.put(i,1);
}
``````

5 5 [2, 2, 2, 2, 1, 1, 1, 1, 1] 19
1 2 [1, 1, 1] 4
1 1 [1, 1, 1] 4
4 2 [1, 1, 1, 1] 10
3 3 [1, 1, 1] 6
3 1 [1, 1, 1] 10
5 5 [1, 1, 1, 1, 1, 2, 2] 14
7 7 [1, 1, 1, 1, 1, 3, 3] 18
5 5 [1, 1, 1, 1, 1, 2, 2, 2, 2] 19
5 5 [2, 2, 2, 2, 1, 1, 1, 1, 1] 19
위 tc 다통과하고 예시 tc 다통과했는데 이제 더이상 뭐가 문제인지 찾기가 힘들어서 질문 올립니다.

###### 작성중인 코드―Solution.java
``````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
82
83
84
85
86
87
88
89
90
import java.util.*;
class Solution {
public int solution(int bridge_length, int weight, int[] truck_weights) {
int weight_count =0;
int number;
Map<Integer,Integer> map = new HashMap<>();
for(int i=0; i<truck_weights.length; i++){
weight_count += truck_weights[i];
if(!queue.isEmpty()){
number = 0;
for(int y=queue.peek(); y<i; y++){
if(weight_count > weight){
if(number == 0){
number = bridge_length-map.get(queue.peek());
weight_count -= truck_weights[queue.poll()];
}else{
number = bridge_length - (map.get(queue.peek())+number);
weight_count -= truck_weights[queue.poll()];
}
}else{
if(map.get(y) < bridge_length)
map.replace(y,map.get(y)+number+1);
else weight_count -= truck_weights[queue.poll()];
}
}
}
map.put(i,1);
}
// int between = 0;
// if(queue.size() == 1){
//     answer += bridge_length - map.get(queue.peek())+1;
// }else{
//     between = bridge_length - map.get(queue.poll());
//     int index = queue.size();
//     for(int i=1; i<=index; i++){
//         int count = map.get(queue.poll());
//         if(count + between+i > bridge_length){
//             answer -= (count + between+i - bridge_length);
//         }
//     }
//     if()
// }
//         for(int i=0; i<queue.size(); i++){

//         }
// int count =0;
// int first =0;
// while(!queue.isEmpty()){
//     if(count == 0){
//         count = bridge_length - map.get(queue.poll());
//         first = count;
//         System.out.println(count);
//     }else{
//         count = bridge_length - (first+map.get(queue.poll()));
//     }
// }
// System.out.println(count);
// if(count > bridge_length){
//     answer -= (count - bridge_length);
// }

//         while(true){
//             int count =0;
//             for(int i=queue.peek(); i<truck_weights.length; i++){
//                 count = map.get(i);
//                 if(count >= bridge_length){
//                     queue.poll();
//                 }
//                 map.replace(i,count+1);
//             }