🐣 알고리즘 삐약/✏️ 냅다 덤벼보는 문제풀이

[프로그래머스] LV2. 택배 배달과 수거하기 | JAVA

우주수첩 2024. 8. 15. 16:40
728x90

https://school.programmers.co.kr/learn/courses/30/lessons/150369

 

프로그래머스

코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.

programmers.co.kr

 

class Solution {
    public long solution(int cap, int n, int[] deliveries, int[] pickups) {
        long answer = 0;
        
        int d=0;
        int p =0;
        for(int i=n-1;i>=0;i--){
            d -= deliveries[i];
            p -= pickups[i];
            
            while(d<0 || p<0 ){
                d+=cap;
                p+=cap;
                answer += (i+1)*2;
            }
            
            
        }
        
        return answer;
        
    }
}

 

 

 

어렵짜나!!! 이런 거 생각 못하자나 나는!!!!

728x90